# parsetrace

> Minimal library for parsing and printing node stacktrace

Latest version **0.2.0** (published 2014-07-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install parsetrace
pnpm add parsetrace
yarn add parsetrace
bun add parsetrace
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2014-07-14 |
| First published | 2014-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Vsevolod Strukchinsky |
| Maintainers | floatdrop |
| Keywords | stack, trace, source, parse |

## Links

- npm: https://www.npmjs.com/package/parsetrace
- Repository: https://github.com/floatdrop/node-parsetrace
- Issues: https://github.com/floatdrop/node-parsetrace/issues
- npm.io page: https://npm.io/package/parsetrace

## Dependencies (1)

- [pff](https://npm.io/package/pff.md) ~0.2.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2014-07-14
- 0.1.5 — 2014-01-02
- 0.1.4 — 2014-01-02
- 0.1.2 — 2014-01-02
- 0.1.1 — 2014-01-02
- 0.1.0 — 2014-01-02
- 0.0.1 — 2014-01-02

## README

# node-parsetrace [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
Minimal library for parsing and printing node stacktrace. Mostly for use in [express-error-with-sources](https://github.com/floatdrop/express-error-with-sources).

## Installation

`npm install --save parsetrace`

## Example

```javascript
var parsetrace = require('parsetrace');

try {
    throw new Error('My cool error');
} catch (e) {
    console.log(parsetrace(e, { sources: true }).json());
}
```

## API

### parsetrace(error, [options], [callback])

Parses stack trace from `Error`, `string` or `object`, that have `.stack` and `.message` property.

If callback is passed - all source code fetching will be async and error will be passed to it (even if `strict` is `true`).

```javascript
parsetrace(err, function(error, trace) {
    console.log(trace.toString());
});
```

__Options__:

 * `sources` - fetch source code from files, that are mentioned in stacktrace. If file can not be found or readed - sources will be fetched silently (unless you enabled `strict` option) (default: `false`)
 * `strict` - throws errors, while parsing stacktrace and fetching source code (default: `false`)
 * `contextSize` - number of lines before and after the error line (default: `3`)

__Returns__ `Object` with methods described below:

### json()

```json
{
    "error": "My cool error",
    "frames": [
        {
            "line": 4,
            "column": 11,
            "function": "Object.<anonymous>",
            "file": "/full/path/to/file.js",
            "source": {
                "2": { "code": "" },
                "3": { "code": "try {" },
                "4": { "code": "    throw new Error('My cool error');" },
                "5": { "code": "} catch (e) {" },
                "6": { "code": "    console.log(parsetrace(e).json());" }
            }
        }
    ]
}
```

__Returns__ stacktrace as Json string

### object()

Format of object you can see in `json()` section.

__Returns__ stacktrace as Object

### toString([options])

__Options__:

 * `excludeSources` - if stacktrace was parsed with sources, this will exclude them from output (default: `false`)

__Returns__ stacktrace as NodeJS formatted stacktracke string.


[npm-url]: https://npmjs.org/package/parsetrace
[npm-image]: https://badge.fury.io/js/parsetrace.png

[travis-url]: http://travis-ci.org/floatdrop/node-parsetrace
[travis-image]: https://secure.travis-ci.org/floatdrop/node-parsetrace.png?branch=master

[depstat-url]: https://david-dm.org/floatdrop/node-parsetrace
[depstat-image]: https://david-dm.org/floatdrop/node-parsetrace.png

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