i-validate
v0.1.4
Published
flexible async object validation
Downloads
4
Readme
i-validate
npm install --save i-validate
validator = require 'i-validate'
validator.setValidations
users:
name: ->
new Promise (resolve) =>
window.setTimeout =>
resolve @.$item
, 4000
age: ['$number', '$min(10)', '$max(40)']
cats:
$validations: '$notEmpty'
name: '$exists'
email: ['$exists', '$emailList']
data =
name: 'jimbo'
age: 18
email: '[email protected];[email protected]'
cats: [
name: 'hope'
age: 6
,
name: 'bobby'
age: 12
]
validator.validate 'users', data
.then (result) ->
console.log 'result', result
add your own validation functions
validator.addValidationFns
$big: ->
@.$item > 1000
$small: ->
@.$item < 0.1