babel-plugin-transform-promise-to-any-promise
v1.0.0babel-plugin-transform-promise-to-any-promise
This plugin transforms Promise
to any-promise
.
Example
export default function main() {
const taskA = getResultAsync(1337);
const taskB = new Promise((resolve, reject) =>
nodeCallbackFunc(42, (err, res) => err ? reject(err) : resolve(res))
);
return Promise.all([taskA, taskB]).then(([resA, resB]) => resA + resB);
}
Gets converted to:
import {all, default as Promise} from 'any-promise';
export default function main() {
const taskA = getResultAsync(1337);
const taskB = new Promise((resolve, reject) =>
nodeCallbackFunc(42, (err, res) => err ? reject(err) : resolve(res))
);
return all([taskA, taskB]).then(([resA, resB]) => resA + resB);
}
Usage
- Install any-promise:
npm install --save any-promise
- Install the promise-to-any-promise plugin:
npm install --save-dev babel-plugin-transform-promise-to-any-promise
- Add transform-promise-to-any-promise to your .babelrc file:
{
"plugins": ["transform-promise-to-any-promise"]
}
If you'r using the transform-runtime plugin add transform-promise-to-any-promise before transform-runtime:
{
"plugins": [
"transform-promise-to-any-promise",
"transform-runtime"
]
}
npm i babel-plugin-transform-promise-to-any-promise
Metadata
- MIT
- Whatever
- Unknown
- released 5/7/2017