composable-validator

0.0.1 • Public • Published

Composable Validator

  npm install composable-validator@latest

This is a convenience package around chriso's node-validator.

This package lets you create validation objects that you can nest, combine and re-use.

Simple "user" validation object:

 
    var userValidator = new schema({
      email: check().len(4, 64).isEmail(),
      password: check().len(4, 80).notIn(["password", "love", "12345"])
    });
 
    var results = userValidator.check({
      email:"ab@c",
      password: "love"
    });
 
    //true
    results.deepEqual({ email: [ 'Invalid email' ], password: [ 'Unexpected value' ] });
    

Nesting!

 
    registrationValidator = new schema({
      subdomain: check().is(/[a-zA-Z][a-zA-Z0-9]*/),
      user: userValidator /* note the re-use! */
    })
 
    var regResult = registrationValidator.check({
      subdomain: "w3",
      user: {
        email: "@gmail.com",
        password: "w00t!!!"
      }
    })
 
    //true
    regResult.deepEqual({ user: { email: [ 'Invalid email' ] } });
 

Readme

Keywords

none

Package Sidebar

Install

npm i composable-validator

Weekly Downloads

2

Version

0.0.1

License

none

Last publish

Collaborators

  • aaronblohowiak