UNPKG

417 BJavaScriptView Raw
1"use strict";
2
3/**
4* Convert a node style fn to a promise
5 */
6
7module.exports = function(fn, ctx) {
8 if(ctx === undefined)
9 ctx = this;
10 return function() {
11 var args = [].slice.apply(arguments);
12
13 return new Promise(function (resolve, reject) {
14 args.push(function (err, res) {
15 if(err)
16 return reject(err);
17 resolve(res);
18 });
19 fn.apply(ctx, args);
20 });
21
22 };
23};