1.0.5 • Published 8 years ago

valichain v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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)
  • lodash's functions:

    • .isNumber(x) => `new V(). $isNumber().validate(x)`
  • chriso/validator's functions:

    • validator.isEmail(x) => new V().v$isEmail().validate(x)

For datailed help about wrapped functions, checks its own documentation:

List of wrapped functions

License

MIT: LICENSE.