validator-factory
@ryanburnette/Description
An implementation of Validate.js as a factory for creating JavaScript object validators.
This library is structured for use in Node.js, but should work fine in the browser if it is packaged with Webpack.
Usage
npm install @ryanburnette/validator-factory
var ValidatorFactory = require('@ryanburnette/validator-factory');
var validate = ValidatorFactory.create({
constraints: {
foo: {
presence: true,
length: {
minimum: 3
}
},
email: {
presence: true,
email: true
}
},
options: {
fullMessages: false
}
});
validate({
email: 'lois.griffin'
})
// => { body: { email: 'lois.griffin' }, validation: { foo: [ "can't be blank" ], email: [ 'is not a valid email' ] } }
validate({
foo: 'abc',
email: 'lois.griffin@gmail.com'
})
// => { body: { foo: 'abc', email: 'lois.griffin@gmail.com' }, validation: false }