1.0.0 • Published 2 years ago

@toadperson/sync-validator-chain v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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'`
//   }
// ]
1.0.0

2 years ago