1.0.0 • Published 9 years ago
validator-codec v1.0.0
validator-codec
Codec for validator presets
Install
$ npm install validator-codec --saveUsage
const codec = require('validator-codec')
const presets = {
username: v => v !== 'steve',
'min-length': (v, min) => v.length >= min,
'username-min-length': ['username', 'min-length:3']
}
codec('username', presets).every(validator => validator('steve')) // false
// 1. More than one rules split with `|`
// 2. Rule name and arguments split with `:`
codec('min-length:3|username')codec(rule, presets , list)
Analysis the rule according to presets, and generates the array list of testers, or append to the existing list(if list argument is provided)
- list
Array=[]optional, defaults to[] - presets
Object - rule
Stringwill be parsed according topresets,function(v)will be added tolistRegExpwill be transformed into a function
Returns Array.<function>
License
MIT