prmzfy
v1.2.8
Published
yet another promisify...
Downloads
23
Readme
prmzfy
Promisify for nodebacks. Requires Promise to be supported by runtime or via polyfill.
Installation
$ npm i prmzfy
Usage
const prmzfy = require('prmzfy');
const readFile = prmzfy(fs.readFile);
readFile('file.txt')
.then(data => ...)
.catch(error => ...);
Promisifying callback with multiple arguments:
const prmzfy = require('prmzfy');
const sumAndProd = (a, b, cb) => {
cb(null, a + b, a * b);
};
const sp = prmzfy(sumAndProd, { multiArgs: true });
sp(3, 4)
.then(([sum, prod]) => console.log(sum, prod));
Don't forget to bind proper context when promisifying prototype methods:
const prmzfy = require('prmzfy');
const foo = new Foo();
const bar = prmzfy(foo.someMethod.bind(foo));
Typescript
This module also contains type declarations.
import * as prmzfy from 'prmzfy';