error-stack
Version:
Parse and manipulate error.stack
106 lines (79 loc) • 2.29 kB
Markdown
[](https://travis-ci.org/kaelzhang/error-stack)
[](https://codecov.io/gh/kaelzhang/error-stack)
<!-- optional appveyor tst
[](https://ci.appveyor.com/project/kaelzhang/error-stack)
-->
<!-- optional npm version
[](http://badge.fury.io/js/error-stack)
-->
<!-- optional npm downloads
[](https://www.npmjs.org/package/error-stack)
-->
<!-- optional dependency status
[](https://david-dm.org/kaelzhang/error-stack)
-->
Parse and manipulate `error.stack`
```sh
$ npm i error-stack
```
```js
const parse = require('error-stack')
const {stack} = new Error('foo')
console.log(stack)
// Error: foo
// at repl:1:11
// at Script.runInThisContext (vm.js:123:20)
const parsed = parse(stack)
parsed.type // Error
parsed.message // foo
parsed.traces
// [
// {
// callee: undefined,
// source: 'repl',
// line: 1,
// col: 11
// },
// {
// callee: 'Script.runInThisContext',
// source: 'vm.js',
// line: 123,
// col: 20
// }
// ]
parsed
.filter(({callee}) => !!callee)
.format()
// Error: foo
// at Script.runInThisContext (vm.js:123:20)
```
Error type
The message used by Error constructor
```ts
interface Source {
// The source of the the callee
source: string
line?: number
col?: number
}
interface Trace extends Source{
callee: string
// Whether the callee is 'eval'
eval?: boolean
// The source location inside eval content
evalTrace: Source
}
```
- **filterFunction** `Function` the same as the callback function of `Array.prototype.filter(callback)`
Filters the current traces
Format object `parsed`
[ ](LICENSE)