JSPM

extract-stack

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1260417
  • Score
    100M100P100Q186072F
  • License MIT

Extract the actual stack of an error

Package Exports

  • extract-stack

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (extract-stack) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

extract-stack Build Status

Extract the actual stack of an error

Install

$ npm install extract-stack

Usage

const extractStack = require('extract-stack');

const error = new Error('Missing unicorn');

console.log(error.stack);
/*
Error: Missing unicorn
    at Object.<anonymous> (/Users/sindresorhus/dev/extract-stack/unicorn.js:2:15)
    at Module._compile (module.js:409:26)
    at Module.load (module.js:343:32)
    at startup (node.js:139:18)
*/

console.log(extractStack(error));
/*
    at Object.<anonymous> (/Users/sindresorhus/dev/extract-stack/unicorn.js:2:15)
    at Module._compile (module.js:409:26)
    at Module.load (module.js:343:32)
    at startup (node.js:139:18)
*/

console.log(extractStack.lines(error));
/*
[
    'Object.<anonymous> (/Users/sindresorhus/dev/extract-stack/unicorn.js:2:15)'
    'Module._compile (module.js:409:26)'
    'Module.load (module.js:343:32)'
    'startup (node.js:139:18)'
]
*/

API

It gracefully handles cases where the stack is undefined or empty and returns an empty string.

extractStack(error)

Returns the actual stack part of the error stack.

extractStack.lines(error)

Returns the stack lines of the error stack without the noise as a string[].

error

Type: Error | string | undefined

Either an Error or the .stack of an Error.

License

MIT © Sindre Sorhus