AJV validator with super powers! See also the AJV full documentation.
You can set the types you want!
const ajv = new Ajv()
ajv.addType('mongoid', {
compile () {
return function (data) {
const re = /^(?=[a-f\d]{24}$)(\d+[a-f]|[a-f]+\d)/i
return re.test(data)
}
}
})
const schema = {
properties: {
user_id: { type: 'mongoid' }
}
}
You can set required property in line:
const schema = {
properties: {
user_id: { type: 'mongoid', required: true }
}
}
And can also set a required property using the '*':
const schema = {
properties: {
'*user_id': { type: 'mongoid' }
}
}
const schema = {
properties: {
'*name': 'string',
'*email': 'email',
'age': 'number',
'*message': 'string',
}
}
node test/
"Simplicity is the ultimate sophistication"
Da Vinci