v-compose

1.2.0 • Public • Published

v-compose

A set of helpers for combining validators

Inspired by this article.

This lib only cares about combining validators. It does not provide any ready-to-use validator functions like isEmail, isRequired, etc. For these purposes you may use other libs, like this one.

install

npm i -S v-compose

Example

import * as V from "v-compose"


const validate = V.validate([
  [ x => x > 0, "not positive" ],
  [ 
    x => x % 2 === 0, 
    x => `'${x}' is not even` 
  ],
])

validate(0) // => "not positive"
validate(1) // => "'1' is not even"


const cfg = [
  x => x !== 3 ? V.ERR_VALID : "value is equal 3",
  validate,
]

const validateAll = V.validateAll(cfg)

validateAll(3) // => [ "value is equal 3", "'3' is not even" ]
validateAll(2) // => []


const isValid = V.isValid(cfg)

isValid(3) // => false

Docs:

License

MIT

Package Sidebar

Install

npm i v-compose

Weekly Downloads

4

Version

1.2.0

License

MIT

Unpacked Size

88.8 kB

Total Files

16

Last publish

Collaborators

  • jeron-diovis