UNPKG

860 BMarkdownView Raw
1# capture-stack-trace
2
3> [Ponyfill](https://ponyfill.com) for [`Error#captureStackTrace`](https://nodejs.org/api/errors.html#errorcapturestacktracetargetobject-constructoropt)
4
5This is useful for creating cross-platform code as `Error#captureStackTrace` is only available in V8-based JavaScript environments like Node.js and Chrome.
6
7## Install
8
9```sh
10npm install capture-stack-trace
11```
12
13## Usage
14
15```js
16import captureStackTrace from 'capture-stack-trace';
17
18const object = {};
19captureStackTrace(object);
20object.stack; // Similar to `new Error().stack`
21```
22
23## API
24
25### captureStackTrace(object)
26
27Creates a `.stack` property on the given `object`, which when accessed returns a string representing the location in the code at which `captureStackTrace()` was called.
28
29**Note:** This ponyfill does not support the second parameter of `Error#captureStackTrace`.