README
Valided
simple validator data, contains asynchronous validation
install
npm install valided
example
import { valided, rules } from 'valided';
// First call, rules is empty
rules.addRule('required', (value) => Boolean(value));
const loginRules = {
user: [
[ 'required', 'user must required' ],
[ (value) => value.length > 5, 'user length must be greater than 5' ]
],
pass: [
[ 'required', 'pass must required' ],
[ (value) => value.length > 5, 'pass length must be greater than 5' ]
],
repass: [
[ 'required', 'repass must required' ],
[ (value, data) => value === data.pass, 'repass must be the same as pass' ]
],
mail: [
[ 'required', 'mail must required' ],
[ /@/, 'Please fill in the standard email address' ]
// or
// rules.addRule('mail', ...)
// [ 'mail', 'Please fill in the standard email address' ]
]
};
let data = {
user: 'taker2',
pass: 'pass33',
repass: 'pass33',
mail: 'asdf@dfsdf'
};
// defaultOptions
let options = {
verifyExistFieldWithData: true,
firstError: true,
fieldFirstError: true,
onDone: errors => console.log('errors:', errors)
}
const thenCallback = (errors) => {
console.log('log errors with then', errors);
};
valided(loginRules, data, options).then(thenCallback);