Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

joi-summarize

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi-summarize

Summarize all joi errors into a single message

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

joi summarize

Combine error messages from a joi error into a summary string.

  • Designed to work with joi result.error objects created with joi's abortEarly: 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 with null or undefined, it returns undefined
  • If you call summarize with any other non-object, it throws a TypeError

How to Run Tests

  • Initial setup
    • git clone this repository
    • npm install
  • npm run test runs unit tests, coverage checks, eslint
  • npm run test-unit runs unit tests only
  • npm run coverage runs nyc/istanbul code coverage and opens the report
  • npm run lint runs eslint static analysis

Stinking Badges

Build Status npm js-standard-style

License: MIT

See LICENSE

FAQs

Package last updated on 16 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc