Validate by rule defined by user.
let validator = require('treeValidator');
validator.readRulesFromFile('rules.json')
// or
validator.setRules({some: {required: true;}});
validator.isValid({some: ''}); //false
//let get errors
let errors = validator.getErrors();
{
type: 'string' || 'number' || 'date' || 'email',
required: true || false,
format: 'dd-MM-yyyy' || 'dd-MM-yy' // for dates
format: 'digitsBeforeComma:digitsAfterComma' // for numbers
format: 'minLen:maxLen' // for strings
}
Works fine with node version 6.9.x. May have issues with earlier releases.
Q: May I add my own validation rules?
A: Yep, have a look here, don't forget to define: {type: 'your-awesome-custom-format', format: true}