Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

error-format

tunnckocore11MIT1.0.1

Allows you to customize the toString method of passed err. Also adds useful properties like line, filename and column to the err object.

add, col, column, custom, customize, err, error, error-format, file, filename, fmt, format, help, helper, line, name, pass, str, string, tostring, useful, util

readme

error-format npmjs.com The MIT License

Allows you to customize the toString method of passed err. Also adds useful properties like line, filename and column to the err object.

code climate standard code style travis build status coverage status dependency status

Install

npm i error-format --save

Usage

For more use-cases see the tests

const errorFormat = require('error-format')

errorFormat

Adds bypassed .toString which you can customize through the fmt function.

Params

  • <err> {Error}: error object/instance
  • [fmt] {Function}: custom format function
  • returns {Error}: what comes from input (instance of error)

Example

var errorFormat = require('error-format')
var err = new TypeError('baz qux')

console.log(err.toString())
// => TypeError: baz qux

err = errorFormat(err, function fmt (headline) {
  if (this.message.indexOf('baz') !== -1) {
    headline += ' --- Line: ' + this.line
  }
  if (this.message.indexOf('qux') !== -1) {
    headline += ' --- Column: ' + this.column
  }
  return headline
})

console.log(err.toString())
// => TypeError: baz qux --- Line: 4 --- Column: 11

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

changelog

1.0.1 - 2016-03-18

1.0.0 - 2016-02-15

  • Release v1.0.0 / npm@v1.0.0
  • add keywords
  • update docs, add example.js
  • implement, official release

0.0.0 - 2016-02-15

  • Initial commit