JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 82820427
  • Score
    100M100P100Q244344F
  • License MIT

Promisify a callback-style function

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 Build Status

Promisify a callback-style function

Install

$ npm install --save pify

Usage

var fs = require('fs');
var pify = require('pify');

pify(fs.readFile)('package.json', 'utf8').then(function (data) {
    console.log(JSON.parse(data).name);
    //=> 'pify'
});

// promisify all methods in a module
var promiseFs = pify.all(fs);

promiseFs.readFile('package.json', 'utf8').then(function (data) {
    console.log(JSON.parse(data).name);
    //=> 'pify'
});

API

pify(input, [promiseModule])

Returns a promise wrapped version of the supplied function.

If the callback of the supplied function gets more than two arguments the result will be an array.

input

Type: function

Callback-style function.

pify.all(module, [promiseModule])

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.

License

MIT © Sindre Sorhus