JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 212
  • Score
    100M100P100Q70106F
  • 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

    • compatible: Boolean if true, pfn can also be used the same as fn
    • promise: Function Promise constructor to be used instead of the native.

Example

var promisify = require('node-promisify');
var glob = promisify(require('glob'));

glob('*.js', { cwd: './files' }).then(function (files) {
    console.log('promisish:', files);
});

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

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

output:

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