JSPM

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

convert function to promise

Package Exports

  • node-promisify

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 (node-promisify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-promisify

Convert callback function to node native promise.

Function name and other own enumberable properties are preserved, as well as the execution context.

Custom promise can be used instead of the native.

Usage

var promisify = require('node-promisify');
promisify(function async(a, b, c, cb) {
    cb(null, d, e, f);
}).then(function (results) {
    // results is [d, e, f]
});

pfn = promisify(fn, opts)

  • fn: Function the async function

  • opts: Object

    • promise: Function Promise constructor to be used instead of the native.

Example

var promisify = require('..');
var glob = promisify(require('glob'));
var path = require('path');

glob('*.js', { cwd: path.join(__dirname, 'files') })
    .then(function (files) {
        console.log('promisish style:', files);
    });

glob('*.js', { cwd: path.join(__dirname, 'files') }, function (err, files) {
    console.log('original style:', files);
});

console.log('other methods:', glob.sync('*.js', { cwd: path.join(__dirname, 'files') }));

output:

⌘ node example/glob.js
other methods: [ 'a.js', 'b.js', 'c.js' ]
original style: [ 'a.js', 'b.js', 'c.js' ]
promisish style: [ 'a.js', 'b.js', 'c.js' ]