An isomorphic validation engine for browser client and node app.
Engine - the core engine inside the validation
npm install --save isomorphic-validation
import isomorphicValidation from isomorphicValidation;
const iv = new isomorphicValidation();
// implement
iv.addValidation({
'required': {
'validator': /^.+$/
}
});
iv.validate({
name: 'name',
value: 'huei90',
type: 'required'
})
.then((val) => console.log('form is valid'))
.catch((val) => console.log('form is invalid'));
given parameter types
const iv = new isomorphicValidation(types)
validator type accepts RegExp
and Function
// adding multiples:
iv.addValidation({'required': {validator: /^.+$/}, age: {validator: /\d+/}})
// adding function:
iv.addValidation({'required': {validator: (v) => !!v})
type format
{
'required': { // validation type name
'validator': /^.+$/ // validation type - RegExp or Function
}
}
validate the form(s) and return Promise
// validate form
iv.validate([{
name: 'name',
value: 'huei',
type: 'required'
},{
name: 'age',
value: 30,
type: 'age']
}])
.then(/* ... */)
.catch(/* ... */);
form format
[{
name: 'name', // form name
value: 'huei', // value of the form name
type: 'required' // type name (given in type format)
}]
iv.getAllTypes(); // => all types
MIT