package
Extract the actual stack of an error
npm install extract-stackGitHub-flavored package documentation.
Across all versions, last 30 days.
4,182,244 in 30 days
Runtime metadata.
Tagged topics.
Extract the actual stack of an error
$ npm install extract-stackimport extractStack from '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)'
]
*/It gracefully handles cases where the stack is undefined or empty and returns an empty string.
Returns the actual stack part of the error stack.
Returns the stack lines of the error stack without the noise as a string[].
Type: Error | string | undefined
Either an Error or the .stack of an Error.
Estimated unpacked size across 1 packages.
5.3 kB
Includes dependencies.