1 | # babel-plugin-transform-async-to-module-method
|
2 |
|
3 | > Turn async functions into a Bluebird coroutine
|
4 |
|
5 | ## Example
|
6 |
|
7 | **In**
|
8 |
|
9 | ```javascript
|
10 | async function foo() {
|
11 | await bar();
|
12 | }
|
13 | ```
|
14 |
|
15 | **Out**
|
16 |
|
17 | ```javascript
|
18 | var Bluebird = require("bluebird");
|
19 |
|
20 | var foo = Bluebird.coroutine(function* () {
|
21 | yield bar();
|
22 | });
|
23 | ```
|
24 |
|
25 | ## Installation
|
26 |
|
27 | ```sh
|
28 | npm install --save-dev babel-plugin-transform-async-to-module-method
|
29 | ```
|
30 |
|
31 | ## Usage
|
32 |
|
33 | ### Via `.babelrc` (Recommended)
|
34 |
|
35 | **.babelrc**
|
36 |
|
37 | Without options:
|
38 |
|
39 | ```json
|
40 | {
|
41 | "plugins": ["transform-async-to-module-method"]
|
42 | }
|
43 | ```
|
44 |
|
45 | With options:
|
46 |
|
47 | ```json
|
48 | {
|
49 | "plugins": [
|
50 | ["transform-async-to-module-method", {
|
51 | "module": "bluebird",
|
52 | "method": "coroutine"
|
53 | }]
|
54 | ]
|
55 | }
|
56 | ```
|
57 |
|
58 | ### Via CLI
|
59 |
|
60 | ```sh
|
61 | babel --plugins transform-async-to-module-method script.js
|
62 | ```
|
63 |
|
64 | ### Via Node API
|
65 |
|
66 | ```javascript
|
67 | require("babel-core").transform("code", {
|
68 | plugins: ["transform-async-to-module-method"]
|
69 | });
|
70 | ```
|