required
required([strict=false])
Effect
Restrict the detect value is not undefined | null | NaN
.
If strict mode is turned on(strict=true), Restrict the detected value is not undefined | null | NaN | '' | {} | []
.
Arguments
[strict]
(boolean) - Whether turn on strict mode, default isfalse
, means no-strict mode. You can exactly setstrict
totrue
to turn on strict mode.
Example
const schema1 = racoon.any();
schema1.validate(undefined); // pass, return: undefined
schema1.validate(null); // pass, return: null
schema1.validate(NaN); // pass, return: NaN
schema1.validate(''); // pass, return: 空字符串
schema1.validate({}); // pass, return: {}
schema1.validate([]); // pass, return: []
const schema2 = racoon.any().required();
schema2.validate(undefined); // fail
schema2.validate(null); // fail
schema2.validate(NaN); // fail
schema1.validate(''); // pass, return: ''
schema1.validate({}); // pass, return: {}
schema1.validate([]); // pass, return: []
const schema3 = racoon.any().required(true);
schema2.validate(undefined); // fail
schema2.validate(null); // fail
schema2.validate(NaN); // fail
schema1.validate(''); // fail
schema1.validate({}); // fail
schema1.validate([]); // fail
Last updated
Was this helpful?