0.1.1 • Published 8 years ago
joi-plain v0.1.1
joi-plain
Validate objects using hapijs/joi and return a
400 - Bad Request
error
install
npm install --save joi-plain
Usage
To create the schemas, use joi :)
const joi = require('joi');
const joiPlain = require('joi-plain');
const schema = joi.object().keys({
field: joi.string().required(),
another: joi.number()
});
const obj = {
another: 123
};
const validation = joiPlain(obj, schema);
if (validation) {
// Yes, error!
/* The object will be:
{
statusCode: 400,
error: 'Bad Request',
message: '"field" is required',
key: 'field'
}
*/
} else {
// No error
}
Development
- Install dependencies
npm install
- Run tests
npm test
Author
License
MIT © Rômulo Alves