0.1.1 • Published 8 years ago

joi-plain v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

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

  1. Install dependencies
npm install
  1. Run tests
npm test

Author

Rômulo Alves

License

MIT © Rômulo Alves

0.1.1

8 years ago

0.1.0

8 years ago