combine-validators
v2.1.1
Published
fluent api for validator.js
Downloads
3
Maintainers
Readme
combine-validators
A Validator gives validator.js string validators a common context and allows composition.
const Validator = require('combine-validators');
const validations = Validator.validations;
const v = new Validator();
v.check(validations.isMandatory, validations.isEmail)(req.body, 'email', 'Email not valid');
v.check(validations.isOptional, validations.isIn('a', 'b', 'c'))(req.body, 'type', 'Type not valid');
v.check(validations.isMandatory, validations.isMongoId)(req.body, '_id', 'Id not valid');
if(v.hasErrors()) console.log('Validation rejected');