promy

1.0.2 • Public • Published

promy

Conditional promisify. Transform callback-based function to callback-and-promise-based one.

Build Status NPM version

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.

// 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

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i promy

    Weekly Downloads

    17

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    3.89 kB

    Total Files

    8

    Last publish

    Collaborators

    • astur