# extract-stack

> Extract the actual stack of an error

Latest version **3.0.0** (published 2021-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install extract-stack
pnpm add extract-stack
yarn add extract-stack
bun add extract-stack
```

## Health

**Score 43/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-04-07 |
| First published | 2017-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/extract-stack) |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 67 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | extract, stack, error, trace, traces, lines, parse, get |

## Links

- npm: https://www.npmjs.com/package/extract-stack
- Repository: https://github.com/sindresorhus/extract-stack
- Homepage: https://github.com/sindresorhus/extract-stack#readme
- Issues: https://github.com/sindresorhus/extract-stack/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/extract-stack

## 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

- 3.0.0 (latest) — 2021-04-07
- 2.0.0 — 2019-04-17
- 1.0.0 — 2017-03-24

## README

# extract-stack

> Extract the actual stack of an error

## Install

```
$ npm install extract-stack
```

## Usage

```js
import 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)'
]
*/
```

## 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`.

## Related

- [clean-stack](https://github.com/sindresorhus/clean-stack) - Clean up error stack traces

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