Package Exports
- pify
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pify 
Promisify a callback-style function
Install
$ npm install --save pify
Usage
const fs = require('fs');
const pify = require('pify');
pify(fs.readFile)('package.json', 'utf8').then(data => {
console.log(JSON.parse(data).name);
//=> 'pify'
});
// promisify all methods in a module
const promiseFs = pify.all(fs);
promiseFs.readFile('package.json', 'utf8').then(data => {
console.log(JSON.parse(data).name);
//=> 'pify'
});
API
pify(input, [promiseModule], [options])
Returns a promise wrapped version of the supplied function.
input
Type: function
Callback-style function.
pify.all(module, [promiseModule], [options])
Returns a version of the module with all its methods promisified.
module
Type: object
Module whose methods you want to promisify.
promiseModule
Type: function
Custom promise module to use instead of the native one.
Check out pinkie-promise
if you need a tiny promise polyfill.
options
multiArgs
Type: boolean
Default: false
By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like request
that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument.
const request = require('request');
const pify = require('pify');
pify(request, {multiArgs: true})('http://sindresorhus.com').then(result => {
const [httpResponse, body] = result;
});
License
MIT © Sindre Sorhus