https://github.com/sindresorhus/capture-stack-trace
Ponyfill for Error#captureStackTrace
https://github.com/sindresorhus/capture-stack-trace
javascript ponyfill
Last synced: about 1 year ago
JSON representation
Ponyfill for Error#captureStackTrace
- Host: GitHub
- URL: https://github.com/sindresorhus/capture-stack-trace
- Owner: sindresorhus
- License: mit
- Created: 2015-07-24T08:50:30.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2022-10-10T14:09:58.000Z (over 3 years ago)
- Last Synced: 2025-03-29T04:26:17.054Z (about 1 year ago)
- Topics: javascript, ponyfill
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 61
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
- Security: .github/security.md
Awesome Lists containing this project
README
# capture-stack-trace
> [Ponyfill](https://ponyfill.com) for [`Error#captureStackTrace`](https://nodejs.org/api/errors.html#errorcapturestacktracetargetobject-constructoropt)
This is useful for creating cross-platform code as `Error#captureStackTrace` is only available in V8-based JavaScript environments like Node.js and Chrome.
## Install
```sh
npm install capture-stack-trace
```
## Usage
```js
import captureStackTrace from 'capture-stack-trace';
const object = {};
captureStackTrace(object);
object.stack; // Similar to `new Error().stack`
```
## API
### captureStackTrace(object)
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.
**Note:** This ponyfill does not support the second parameter of `Error#captureStackTrace`.