https://github.com/skyksandr/babel-plugin-transform-catch
https://github.com/skyksandr/babel-plugin-transform-catch
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/skyksandr/babel-plugin-transform-catch
- Owner: skyksandr
- Created: 2019-04-16T15:49:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T07:35:24.000Z (over 3 years ago)
- Last Synced: 2025-03-14T22:41:25.872Z (over 1 year ago)
- Language: JavaScript
- Size: 373 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Motivation
`catch` in Google apps script is reserved word and this make it impossible to use
with promises. And while you can easily overcome it by not using promises which in
fact absent in GAS environment the problem become hard to solve if your project
requires 3rd-party library. In example `jsonwebtoken`, which dependent on another
library, which has `.catch` in its code.
At the end of the day it become simpler to roll-out babel transformation than any
other option.
## Example
**In**
```js
performRequest.then(doSomething).catch(function() { handler() });
```
**Out**
```js
performRequest.then(doSomething)["catch"](function () {
handler();
});
```
## Installation
```sh
$ npm install babel-plugin-transform-catch
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["babel-plugin-transform-catch"]
}
```
### Via CLI
```sh
$ babel --plugins babel-plugin-transform-catch script.js
```
### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["babel-plugin-transform-catch"]
});
```