promo.js
Convert node-style callback-based functions into promise-based equivalents for easier composition.
Installation
$ npm i promo
Usage
var promo = ; // Take a standard function...var { // callback is eventually called with two arguments - an error // (if applicable) and the result;}; // ...and create a promise-returning equivalentvar promisified = ; // Then, instead of doing this...; // ...do this:;
Real-world example:
var readFile = writeFile = glob = mkdirp = ;
If necessary, you can pass in the context as a second argument:
var someModule = { // because this method uses `this`, we need to // pass in a context this; }; var promisified = ;
If you convert a function that references this
, and don't pass in a context, promo will warn you about it.
Any properties of the function are available after it has been promisified:
var glob = ;var matches = glob; // still works
The Promise
object used under the hood is exposed as promo.Promise
.
Credits
This module uses es6-promise by Jake Archibald.
License
MIT.