Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/neat-stack
Make a color-coded stack trace from an error
https://github.com/shinnn/neat-stack
beautify colored error errors javascript log nodejs readability stacktrace terminal
Last synced: 26 days ago
JSON representation
Make a color-coded stack trace from an error
- Host: GitHub
- URL: https://github.com/shinnn/neat-stack
- Owner: shinnn
- License: isc
- Created: 2017-05-09T10:28:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-05T10:10:32.000Z (over 5 years ago)
- Last Synced: 2024-04-15T00:04:36.311Z (7 months ago)
- Topics: beautify, colored, error, errors, javascript, log, nodejs, readability, stacktrace, terminal
- Language: JavaScript
- Homepage: https://npm.runkit.com/neat-stack
- Size: 89.8 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# neat-stack
[![npm version](https://img.shields.io/npm/v/neat-stack.svg)](https://www.npmjs.com/package/neat-stack)
[![Build Status](https://travis-ci.com/shinnn/neat-stack.svg?branch=master)](https://travis-ci.com/shinnn/neat-stack)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/neat-stack.svg)](https://coveralls.io/github/shinnn/neat-stack?branch=master)Make a color-coded stack trace from an error
```javascript
const neatStack = require('neat-stack');
const request = require('request');request('foo', err => console.error(neatStack(err)));
```Useful for CLI applications — stack traces are not very important for end users but needed for authors to receive meaningful bug reports.
## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install neat-stack
```## API
```javascript
const neatStack = require('neat-stack');
```### neatStack(*error*)
*error*: `Error`
Return: `string`It returns a refined [`Error#stack`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack):
* Red-colored by [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code).
* Lines starting with `' at'` are dimmed.
* [Any lines from Node.js internals are omitted](https://github.com/sindresorhus/clean-stack).
* Paths are simplified by [replacing a home directory with `~`](https://github.com/shinnn/tilde-path) on POSIX.```javascript
const error = new Error('Hi');error.stack; /* => `Error: Hi
at Object. (/Users/example/run.js:1:75)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)` */neatStack(error); /* => `\u001b[31mError: Hi\u001b[2m
at Object. (~/example/run.js:1:88)\u001b[22m\u001b[39m` */
```## License
[ISC License](./LICENSE) © 2017 - 2019 Shinnosuke Watanabe