node-style-promisify
v0.1.1
Published
Convert any Node.js-style callback API into a function that returns an ES6 promise
Downloads
2
Readme
Installation
$ npm i node-style-promisify
[email protected] node_modules/node-style-promisify
$
Example
import fs from 'fs';
import promisify from 'node-style-promisify';
const readFile = promisify(fs, fs.readFile);
readFile('file.txt', 'utf8').then(([ data ]) => {
process.stdout.write(data);
}).catch(error => {
console.error(error.toString());
});
API
promisify(thisArg, func)
thisArg
The value ofthis
to be passed tofunc
when it is calledfunc
The function to call via the wrapper
Returns a wrapper around func
that returns a Promise
object when called.