joi-error-formatter

Display multiple Joi Errors in one line

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
joi-error-formatter
200.5.35 years ago5 years agoMinified + gzip package size for joi-error-formatter in KB

Readme

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