format

format(callback, [ctx])

Effect

Format the final return value of validate and validateSilent, the return value of callback will be the final return value.

Arguments

  • callback (function) - The format function. The function has an argument: the return value returned by validate. The return value of callback is recommended but not necessarily to be the type of the schema declared.

  • [ctx] (*) - The execution context of callback.

Example

const schema = racoon.number();
schema.validate(1.2).format(num => num.toFixed(2)); // pass, 返回 '1.20'

Last updated