1 | # capture-stack-trace
|
2 |
|
3 | > [Ponyfill](https://ponyfill.com) for [`Error#captureStackTrace`](https://nodejs.org/api/errors.html#errorcapturestacktracetargetobject-constructoropt)
|
4 |
|
5 | This 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
|
10 | npm install capture-stack-trace
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | import captureStackTrace from 'capture-stack-trace';
|
17 |
|
18 | const object = {};
|
19 | captureStackTrace(object);
|
20 | object.stack; // Similar to `new Error().stack`
|
21 | ```
|
22 |
|
23 | ## API
|
24 |
|
25 | ### captureStackTrace(object)
|
26 |
|
27 | Creates 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`.
|