smart-promisify
A smart implementation of promisify using native promises
Install
npm i smart-promisify
Features
With smart-promisify you can obviously wrap asynchronous functions so they return a promise.
But why smart?
The smart thing about this promisify module is, that you can use the wrapped function just like before. If you provide a callback, no promise will be returned. If you don't provide a callback, you will get your promise.
You can also change the this object of the wrapped function. If you use .apply, .call or .bind on the wrapper, the this object will also be applied to the wrapped function.
Example - Promisify fs.mkdir
const fs = const promisify = // create an async function so we can await stuff { // wrap the fs.mkdir method let mkdir = // await the promise returned by the wrapper await // you can still provide a callback. // the wrapper will return the return value of the fs.mkdir instead of a promise // changing the this of the promisified function mkdir // fs.mkdir will now have fs as its this object // alternatively you can call the promisify function with a second argument. mkdir = // the second argument will be used as this object for the wrapped function, if it isn't changed afterwards by with call, bind or apply}