Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaelzhang/error-stack
Parse and manipulate error-stack
https://github.com/kaelzhang/error-stack
error
Last synced: 17 days ago
JSON representation
Parse and manipulate error-stack
- Host: GitHub
- URL: https://github.com/kaelzhang/error-stack
- Owner: kaelzhang
- License: other
- Created: 2019-06-12T06:50:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-17T22:43:20.000Z (about 3 years ago)
- Last Synced: 2024-04-15T12:32:58.289Z (7 months ago)
- Topics: error
- Language: JavaScript
- Size: 14.6 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/kaelzhang/error-stack.svg?branch=master)](https://travis-ci.org/kaelzhang/error-stack)
[![Coverage](https://codecov.io/gh/kaelzhang/error-stack/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/error-stack)# error-stack
Parse and manipulate `error.stack`
## Install
```sh
$ npm i error-stack
```## Usage
```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)
```### parsed.type `string`
Error type
### parsed.message `string`
The message used by Error constructor
### parsed.traces `Array`
```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
}
```### parsed.filter(filterFunction): this
- **filterFunction** `Function` the same as the callback function of `Array.prototype.filter(callback)`
Filters the current traces
### parsed.format(): string
Format object `parsed`
## License
[MIT](LICENSE)