default
default(value, [strict=false], [ctx])
Effect
Set the return value of validate and validateSilent, when the detected value is undefined | null | NaN.
If strict mode is turned on(strict=true), set the return value when the detected value is undefined | null | NaN | '' | {} | [].
Arguments
value(*) The default return value ofvalidateandvalidateSilent. Whenvalueis a function, then set the return value ofvalueto be the default return value. The function has a parameter: the original detected value -undefined,nullNaN, ''',{}or[].[strict](boolean) - Whether turn on strict mode, default isfalse, means no-strict mode. You can exactly setstricttotrueto turn on strict mode.[ctx](*) The execution context ifvalueis a function.
Example
const schema1 = racoon.any().default(1);
schema1.validate(undefined); // pass, return: 1
schema1.validate(null); // pass, return: 1
schema1.validate(NaN); // pass, return: 1
const schema2 = racoon.any().default(1, true);
schema2.validate(undefined); // pass, return: 1
schema2.validate(null); // pass, return: 1
schema2.validate(NaN); // pass, return: 1
schema2.validate(''); // pass, return: 1
schema2.validate({}); // pass, return: 1
schema2.validate([]); // pass, return: 1Last updated
Was this helpful?