Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

validate-it

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-it

declarative validator

  • 0.2.5
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 15 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc