Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

vladkosinov/validate-it

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

validate-it

Decalarative validator for JS

NPM version Build Status Coverage Status Dependency Status devDependency Status

Installation

$ npm install validate-it

Usage

var validateIt = require('validate-it');

At least you must specify the name of the object to validate

It's check that data's property password is not undefined:

var rule = {name: 'password'};
var data = {password: 'qwerty'};

validateIt(data, rule); // => {}

Rules can be an array:

var rules = [
    {name: 'password'}, 
    {name: 'login'}
];
var data = {password: 'qwerty'};

validateIt(data, rules); // => { login: 'Is required' }

Built-in validators

Will be used only if it is declared in the rule!

empty

var data = {login: ''};
var rule = {name: 'login', empty: false};

validateIt(data, rule); // => { login: 'Is empty' }

len

var data = {login: 'short'};
var rule = {
    name: 'login',
    len: [9, 20]
};
validateIt(data, rule); // => { login: 'Expected [9,20] symbols. Given: 5' }
var data = {login: 'short'};
var rule = {name: 'login', len: 6};
validateIt(data, rule); // => { login: 'Expected min 6 symbols. Given: 5' }

License

MIT

About

Decalarative validator for JS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published