0.1.0 • Published 7 years ago
ian-validator v0.1.0
ian-validator
Validates an input document against a schema.
Usage
const document1 = {
username: 'su'
}
const document2 = {
name: 'Dawg Man',
email: 'dawg@man.com',
username: 'dawg'
}
const schema = {
name: {
type: 'string',
isRequired: true
},
email: {
type: 'string',
isEmail: true
},
username: {
minChars: 3,
maxChars: 16
}
}
ianValidator(document1, schema)
.then(result => {}) // result is `false`.
ianValidator(document2, schema)
.then(result => {}) // result is an object similar to `document2`.
// (in this case it is a straight copy.)
Schema Spec
const schema = {
property: {
type: 'string'|'number'|'regexp'|'object'|'array',
isEmail: true|false,
isRequired: true|false,
minChars: Number, // if type: 'string'
maxChars: Number, // if type: 'string'
minValue: Number, // if type: 'number'
maxValue: Number, // if type: 'number'
transform: function (value) {}
check: function (value) {} // custom validation function, must return/resolve boolean.
}
}
LICENSE: MIT