Useful, powerful and simple object validation based on a schema object with rules that can be glob pattern, regexp, string, array, function or dot property paths like
a.b.c
for nested objects.
npm i thron --save
npm test
For more use-cases see the tests
var schema = require('thron')
var validate = schema({
name: 'foo*',
username: ['jonschlin*', 'tunncko*'],
info: function (val) {
return typeof val === 'string' && val.indexOf('qux') !== -1
},
'user.age': /\d{5}/g,
'user.name': 'Charlike'
})
var result = validate({
name: 'foobar',
username: 'tunnckoCore',
info: 'foo bar baz',
user: {
age: 22,
name: 'Jon'
}
})
console.log(result)
//=> { name: 'foobar', username: 'tunnckoCore' }
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.