default

default(value, [ctx])

Effect

Set the return value of validate and validateSilent, when the detected value is undefined | null.

Arguments

  • value (*) - The default return value of validate and validateSilent. It is recommended but not necessarily to be a boolean. When value is a function, then set the return value of value to be the default return value. The function has a parameter: the original detected value - undefinedor null.

  • [ctx] (*) - The execution context if value is a function.

Example

const schema = racoon.boolean().default(false);
schema.validate(undefined); // pass, return: false
schema.validate(null); // pass, return: false

Last updated