@toadperson/sync-validator-chain
v1.0.0
Published
Module for data validation and coercion.
Downloads
1
Readme
sync-validator-chain
sync-validator-chain is a simple wrap for powerful validator.js lib that allows you to chain validation rules. Inspired by another grate lib express-validator.
Usage
const {check, conform, isValid, validationErrors} = require('@toadperson/sync-validator-chain')
const chain1 = check('10').isInt({min: 1}).toInt()
const chain2 = check('0').isInt({min: 1}).toInt()
// conform
conform(chain1) // 10
conform(chain2) // null
// isValid
isValid(chain1) // true
isValid(chain2) // false
// validationErrors
validationErrors(chain1) // []
validationErrors(chain2) // returns errors info
// [
// {
// fn: 'isInt',
// param: '0',
// message: `isInt({"min":1}) failed with '0'`
// }
// ]