valichain
v1.0.5
Published
Validator chain which wraps several functions of String, lodash and chriso/validator
Downloads
6
Maintainers
Readme
Valichain
Validator chain which wraps several functions of String, lodash and chriso/validator.
Installation
npm install valichain
Usage
var Valichain = require("valichain");
var _ = require("lodash");
// Reusable rules
var rules = {
command : new Valichain().default('play')
._$isNotNil().msg("Must not be null nor undefined")
.s$trim()
.v$isIn(['play', 'pause']).msg("Must be one of play or pause")
};
var data = {
// command : ''
};
data = Valichain.extract(Valichain.validate(rules, data));
console.log(data);
Documentation
For documentation of the Valichain class and its own methods, see doc.md. Besides, several methods of String, lodash and chriso/validator are wrapped and used with a prefix followed by a '$'. The first argument of the wrapped function is automatically replaced by the current value being validated, so do not pass it.
Samples of usage of wrapped functions
String's functions:
- x.trim() =>
new V().s$trim().validate(x)
- x.trim() =>
lodash's functions:
- _.isNumber(x) =>
new V(). _$isNumber().validate(x)
- _.isNumber(x) =>
chriso/validator's functions:
- validator.isEmail(x) =>
new V().v$isEmail().validate(x)
- validator.isEmail(x) =>
For datailed help about wrapped functions, checks its own documentation:
List of wrapped functions
License
MIT: LICENSE.