promy
Conditional promisify. Transform callback-based function to callback-and-promise-based one.
Install
npm install promy
Usage
If you have some async function getting calback as second parameter you can do something like this:
const promy = require('promy');
const fn = promy(
require('./someAsyncCallbackBasedFunction')
);
Now promisified function can be used in two ways. It can return promise if called with only one first argument, or it can run callback if it given as second argument.
fn(arg, (err, res) => {
console.log(err ? err : res);
});
fn(arg)
.then((res) => console.log(res))
.catch((err) => console.log(err));
License
MIT