node-veee

1.1.0 • Public • Published

veee

Object schema validation inspired by joi (almost the same, but async and extensible)

Installation

$ npm install node-veee --save

Usage

 
var V = require('node-veee');
 
var v = new V([options]);
 
v.use(function(v) {
  v.register('number', function(value, context, cb) {
    if (typeof value === 'number' && value === value) return cb();
    cb('is not a number');
  });
  
  v.register('number', 'integer', function(value, context, cb) {
    if (parseInt(value.toString(), 10) === value) return cb();
    cb('is not an integer');
  });
  
  v.register('number', 'positive', function(value, context, cb) {
    if (value > 0) return cb();
    cb('is not a positive number');
  });
})
 
v.validate(5, v.number().positive().integer(), function(err, result) {
  // null, 5
});
 
v.validate(-1, v.number().positive(), function(err, result) {
  // { type: 'number', name: 'positive', path: '_', value: -1, error: 'is not a positive number' }, undefined
});
 
var date = new Date();
 
v.validate(date, v.or(v.date(), v.string().isodate()), ...);

Build-in types

veee is trying to be very similar to joi. it contains a few build-in validators:

  • number
  • string
  • boolean
  • array
  • object
  • date
  • function
  • any (inherited by all types)

TODO

  • update documentation

Readme

Keywords

none

Package Sidebar

Install

npm i node-veee

Weekly Downloads

17

Version

1.1.0

License

MIT

Last publish

Collaborators

  • rusintez