Function used to ensure a value conforms to a specific rule.
example
exportfunctionvalueMatches(field, message) { // return a validator that matches the given value // against another value in the source object; if // they aren't equal, throws a ValidationError returnasyncfunctionvaluesMatch(proposed, current, source) { if (!isEqual(proposed, get(source, field))) throwerrors.error(message, { field, current, proposed, name:'ValidationError', }); }; }
// usage: constsignup = validators.object({ email:validators.string('email is required'), confirm:valueMatches('email', 'emails do not match'), }, 'signup information is invalid');
Function used to ensure a value conforms to a specific rule.