Default

This method will set a default value that will be used when you pass null or undefined or even when you don't pass any value to the validate method

import Schema from "@rapidom/schema";

const Validator = Schema.number().default(0);

// All these cases will return 0
Validator.validate();
Validator.validate(null);
Validator.validate(undefined);

Once the default value is set, there's no use to make the validator required anymore

The default value must match all the validation rules as it's treated as a normal value

Last updated