v-compose
v1.2.0
Published
Easy validators composing
Downloads
6
Maintainers
Readme
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