0.1.1 • Published 9 years ago
joi-plain v0.1.1
joi-plain
Validate objects using hapijs/joi and return a
400 - Bad Requesterror
install
npm install --save joi-plainUsage
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 testAuthor
License
MIT © Rômulo Alves