validator-codec
Codec for validator presets
Install
$ npm install validator-codec --save
Usage
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
-
String
will be parsed according topresets
, -
function(v)
will be added tolist
-
RegExp
will be transformed into a function
-
Returns Array.<function>
License
MIT