joi-error-formatter

0.5.3 • Public • Published

Joi error formatter

dotenv

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

Package Sidebar

Install

npm i joi-error-formatter

Weekly Downloads

79

Version

0.5.3

License

MIT

Last publish

Collaborators

  • nivesh2