1.1.0 • Published 8 years ago
joi-summarize v1.1.0
joi summarize
Combine error messages from a joi error into a summary string.
- Designed to work with joi
result.error
objects created with joi'sabortEarly: false
option
How to Install
npm install --save joi-summarize
How to Use in node.js
'use strict'
const joi = require('joi')
const summarize = require('joi-summarize')
const badInput = {
age: -2,
name: 42
}
const schema = joi.object().keys({
age: joi.number().integer().min(0),
name: joi.string()
})
const result = schema.validate(badInput, {abortEarly: false})
console.log(summarize(result.error))
/* That will log:
Invalid input.
"age" must be larger than or equal to 0.
"name" must be a string.
*/
// To customize the first line message, pass as 2nd argument
console.log(summarize(result.error, 'Unacceptable data'))
/* That will log:
Unacceptable data.
"age" must be larger than or equal to 0.
"name" must be a string.
*/
Invalid arguments
- If you call
summarize
withnull
orundefined
, it returnsundefined
- If you call
summarize
with any other non-object, it throws aTypeError
How to Run Tests
- Initial setup
- git clone this repository
npm install
npm run test
runs unit tests, coverage checks, eslintnpm run test-unit
runs unit tests onlynpm run coverage
runs nyc/istanbul code coverage and opens the reportnpm run lint
runs eslint static analysis
Stinking Badges
License: MIT
See LICENSE