Validio
A Node.js type less schema validation for model, objects and data formats. Also, Validio can run as Synchronous and as Promise implementation too, see more at Validio Npm.
How to install
npm install --save validio
How to use it
First we need to generate the schema to validate an object where name
is a string
which max length
is 20
, and field age
is an int
which max value
is 100
:
var validio = validio;
It will generate the next schema
name: validators: isString: {} isLength: args: length: 20 required: true length: 20 type: 'string' lastName: validators: isString: {} isLength: args: length: 20 length: 20 type: 'string' age: validators: isInt: args: max: 100 type: 'int'
In this case we will use the Person class, and will validate object instances using the schema:
{ thisname = name; thisemail = email; thisage = age; thisphone = phone; thisbirth = birth; thisheight = height;};
Then we can validate the object using the schema, in this case it will validate the name
and age
because those are the only fields that appears on the schema.
var person = 'Joe' 'joe@joe.com' 45; var result = validio; if!resultisValid console; forerror in resulterrors console;else console;
Validio as Promise
We can use Validio as Promise implementation, in the next sample we will use the same schema we build before.
var validio = aspromise; var schema = validio;var person = 'Joe' 'joe@joe.com' 45; validio;
New Features
- Adding support for ArrayTypes
- Fully supporting Basic ArrayType
- Fully supporting Schema Relations with ArrayType
Disclaimer
Strictly supporting packages up to next versions: