promy

Conditional promisify

  • promy

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
promy
001.0.26 years ago7 years agoMinified + gzip package size for promy in KB

Readme

promy
Conditional promisify. Transform callback-based function to callback-and-promise-based one.
!Build Statustravis-imagetravis-url !NPM versionnpm-imagenpm-url

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.

```js
// callback way:

fn(arg, (err, res) => {
    console.log(err ? err : res);
});


//promise way:

fn(arg)
    .then((res) => console.log(res))
    .catch((err) => console.log(err));

License

MIT