vdr

0.0.1-beta3 • Public • Published

vdr

vdr is a simple, pluggable library for validating stuff.

Features Todo:

  • A robust set of validation methods for strings, numbers, dates, etc.
  • Sanitization and type coercion of user input.
  • Lightweight schema definitions for validating entire objects at once.
  • User-friendly, customizable error messages.
  • Flexible, pluggable interface for custom validators and behavior.

Installation

# note: not actually in the npm registry yet... 
$ npm install vdr

Quick Examples

var vdr = require('vdr')();
 
var agent = { name: 'James Bond', age: '007' };
 
// validation constraints are simple:
vdr.string().validate(agent.name);
// null (all good!)
 
// constraints can be chained together:
vdr.number().min(0).validate(agent.age);
// 'value must be a number' (wrong type!)
 
// let's try again...
vdr.number().min(0).convert().validate(agent.age);
// null ('007' --> 7)
 
// usually we want to validate entire objects at once, though:
var schema = vdr({
    name: vdr.string(),
    age: vdr.number().min(0)
});
schema.validate(agent);
// { age: 'age must be a number' }

License

The MIT License (MIT)

Copyright (c) 2014 SPARC.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i vdr

Weekly Downloads

15

Version

0.0.1-beta3

License

MIT

Last publish

Collaborators

  • jmar777
  • sjonnet