Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niksy/babel-plugin-native-error-extend
Babel plugin for native `Error` extending.
https://github.com/niksy/babel-plugin-native-error-extend
Last synced: about 2 months ago
JSON representation
Babel plugin for native `Error` extending.
- Host: GitHub
- URL: https://github.com/niksy/babel-plugin-native-error-extend
- Owner: niksy
- License: mit
- Created: 2020-08-12T10:51:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-22T09:27:28.000Z (over 1 year ago)
- Last Synced: 2024-04-24T14:58:07.665Z (8 months ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# babel-plugin-native-error-extend
[![Build Status][ci-img]][ci]
Babel plugin for native `Error` extending.
Handles all ususal cases such as classic extend and `constructor` override.
## Install
```sh
npm install babel-plugin-native-error-extend --save
```## Usage
Use it via available [plugin activation options][babel-plugins].
For `.babelrc` file:
```json
{
"plugins": ["babel-plugin-native-error-extend"]
}
```Then, in your code:
```js
/* Before */class Becky extends Error {}
/* After */
class Becky extends Error {
constructor(message, options) {
super(message, options);
this.name = this.constructor.name;
this.message = message;if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = new Error(message).stack;
}
}
}
```Check test fixtures ([actual](test/fixtures/classes.js) and
[expected](test/fixtures/classes.expected.js)) for more examples.## Acknowledgments
- [`extendable-error-class`](https://github.com/brillout/extendable-error-class)
- [`custom-error-class`](https://github.com/mafintosh/custom-error-class)
- [`extensible-error`](https://github.com/justmoon/extensible-error)
- [`es6-error`](https://github.com/bjyoungblood/es6-error)## License
MIT © [Ivan Nikolić](http://ivannikolic.com)
[ci]: https://github.com/niksy/babel-plugin-native-error-extend/actions?query=workflow%3ACI
[ci-img]: https://github.com/niksy/babel-plugin-native-error-extend/workflows/CI/badge.svg?branch=master
[babel-plugins]: http://babeljs.io/docs/plugins/