Object Schema Validator
A small library that validates objects according to schemas
It basically receives the object
and a schema
and return a new object with errors, otherwise an empty object, It can manage deep objects.
Installation
npm install object-schema-validate
Usage
- ##### Simple Example
// importvar Validator = ;// Give some valuesvar values = email: 'not an email' ;// Give set up the schemavar schema =;// validate itschemaconsole
Result:
{ email: [ 'Valid email is required' ] }
Now if{}
- ##### Advance example with a deep object and using a library (is.js)
var Validator = ;var is = ;var values =terms_of_service: falseuser:"email": "hola""name": 12342company:"email": "hola"var schema =
Result:
{
terms_of_service: ['Acept terms of service please'],
user: {
email: ['A valid email s required', 'Only letters'],
name: ['Name is required']
},
company: {
email: ['A valid email s required', 'Only letters'],
name: ['Name is required']
}
}
Tests
npm test
Contributing
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.