0.11.2 • Published 9 years ago
@relekang/validator v0.11.2
Validator
Install
npm i --save @relekang/validator
Usage
var Validator = require('@relekang/validator')
var validator = Validator({
field: { required: true }
})
validator.validate(['field'], {})
// => { field: { field: 'field', rule: 'required', value: undefined } }
Adding new rules
var validatorCreator = require("@relekang/validator").extend;
var Validator = validatorCreator({
mod: (field, value, options) => value % options.constant === 0 ? null : 'mod'
});
Validator({ f: { mod: { constant: 2 } }).validate(['f'], { f: 3 })
// => { f: { field: 'f', rule: 'mod', value: 3 } }
Creating rules
A rule is a function that takes three arguments: field, value and options. It then validates the value based on a given conditions and
returns null
if the value validates. If not it should return the name of the
rule that did not validate. A rule can have sub-rules (e.g. numeric validation with max value). It should then return 'rule/sub-rule'
if the data does not validate.
0.11.2
9 years ago
0.11.1
9 years ago
0.11.0
9 years ago
0.10.1
9 years ago
0.10.0
9 years ago
0.9.2
9 years ago
0.9.1
9 years ago
0.9.0
9 years ago
0.8.1
9 years ago
0.8.0
9 years ago
0.7.1
9 years ago
0.6.0
9 years ago
0.5.0
9 years ago
0.4.3
9 years ago
0.4.2
10 years ago
0.4.1
10 years ago
0.4.0
10 years ago
0.3.0
10 years ago
0.2.0
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago