babel-plugin-promise
Turn any callback into promise
Basic promisify using leading comments
ES7 Async/Await + Arrow functions
via NPM
npm install babel-plugin-promise --save-dev
via YARN
yarn add babel-plugin-promise --dev
Basic
before
var fs = ;//@promisify<err,data> promiseName__ = fs;
after
var fs = ;//@promisify<err,data> promiseName { return { fs; };} ;
Without error handling.
If the callback does not return us the error message, insert null
instead of error
before
var fs = ;//@promisify<null,data> promiseName__ = fs;
after
var fs = ;//@promisify<null,data> promiseName { return { fs; };}
You can see that it does not handle reject
Using your own arguments
For custom arguments
before
//@promisify<err,data> findUser__ = User;
after
//@promisify<err,data> findUser { return { User; };}
ES7 Async/Await
This time you should use trailing comments
before
var fs = ; { await fs //@promisify<err,data>}
after
var fs = ; { await { fs; }; //@promisify<err,data>}
ES7 Async/Await + Arrow functions
Also, you can make promises with an arrow function expression
before
var fs = ; const some = async await fs; //@promisify<err,data>
after
var fs = ; const some = async await { fs;}; //@promisify<err,data>