# error-stack2

> Parse and manipulate error.stack

Latest version **2.0.7** (published 2024-06-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install error-stack2
pnpm add error-stack2
yarn add error-stack2
bun add error-stack2
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.7 |
| Published | 2024-06-09 |
| First published | 2021-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 157.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kaelzhang |
| Maintainers | bluelovers |
| Keywords | error-stack, error-stack-parser, formatter, trace, create-by-yarn-tool, create-by-tsdx |

## Links

- npm: https://www.npmjs.com/package/error-stack2
- Repository: https://github.com/bluelovers/error-stack
- Homepage: https://github.com/bluelovers/error-stack#readme
- Issues: https://github.com/bluelovers/error-stack/issues
- npm.io page: https://npm.io/package/error-stack2

## Dependencies (5)

- [ts-type](https://npm.io/package/ts-type.md) ^3.0.1
- [err-code](https://npm.io/package/err-code.md) ^3.0.1
- [crlf-normalize](https://npm.io/package/crlf-normalize.md) ^1.0.20
- [string-split-keep2](https://npm.io/package/string-split-keep2.md) ^1.0.12
- [string-detect-indent](https://npm.io/package/string-detect-indent.md) ^1.0.7

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 2.0.7 (latest) — 2024-06-09
- 2.0.5 — 2023-10-19
- 2.0.4 — 2022-09-26
- 2.0.3 — 2022-08-30
- 2.0.2 — 2022-02-02
- 2.0.1 — 2022-02-02
- 1.0.18 — 2022-02-01
- 1.0.17 — 2021-12-06
- 1.0.15 — 2021-12-06
- 1.0.14 — 2021-12-06
- 1.0.13 — 2021-12-06
- 1.0.12 — 2021-08-22
- 1.0.11 — 2021-08-22
- 1.0.10 — 2021-08-22
- 1.0.9 — 2021-08-22
- … 5 more at https://npm.io/package/error-stack2/versions

## 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)
<!-- optional appveyor tst
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/error-stack?branch=master&svg=true)](https://ci.appveyor.com/project/kaelzhang/error-stack)
-->
<!-- optional npm version
[![NPM version](https://badge.fury.io/js/error-stack.svg)](http://badge.fury.io/js/error-stack)
-->
<!-- optional npm downloads
[![npm module downloads per month](http://img.shields.io/npm/dm/error-stack.svg)](https://www.npmjs.org/package/error-stack)
-->
<!-- optional dependency status
[![Dependency Status](https://david-dm.org/kaelzhang/error-stack.svg)](https://david-dm.org/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<Trace>`

```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)

---
_Source: https://npm.io/package/error-stack2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
