Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    composable-validatorpublic

    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' ] } });
     

    Keywords

    none

    install

    npm i composable-validator

    Downloadsweekly downloads

    1

    version

    0.0.1

    license

    none

    last publish

    collaborators

    • avatar