validator-codec

1.0.0 • Public • Published

Build Status

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 to presets,
    • function(v) will be added to list
    • RegExp will be transformed into a function

Returns Array.<function>

License

MIT

Package Sidebar

Install

npm i validator-codec

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • kael