0.5.3 • Published 7 years ago
joi-error-formatter v0.5.3
Joi error formatter
Returns single error message for multiple errors messages in joi error object. Features:
- Zero-dependency,
- Simple and clean,
- less than 20 lines,
- Easy enough to add your own customizations on to it.
Install
npm install joi-error-formatter --save
Usage
Require it in your entry file:
const joiErrorFormatter = require('joi-error-formatter')
const {error, value} = Joi.validate({ a: 'a string',b:'helloWorld' }, {a: Joi.number(),b:Joi.date()},{ abortEarly: false })
let message = ''
if(error){
// message contains all the errors
message = joiErrorFormatter(error)
}
console.log(message)
/* output:
"a" must be a number,"b" must be a number of milliseconds or valid date string
*/
That's it.
Development Setup steps:
- clone the repo
- npm install --save-dev eslint-config-airbnb-base eslint eslint-plugin-import
- npm install