Skip to content

Commit b5b82ac

Browse files
committed
Implement promises.promisify() without bluebird
1 parent 57cad9c commit b5b82ac

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/docx/files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exports.uriToPath = uriToPath;
1515
function Files(base) {
1616
function read(uri, encoding) {
1717
return resolveUri(uri).then(function(path) {
18-
return readFile(path, encoding).caught(function(error) {
18+
return readFile(path, encoding).catch(function(error) {
1919
var message = "could not open external image: '" + uri + "' (document directory: '" + base + "')\n" + error.message;
2020
return Promise.reject(new Error(message));
2121
});

lib/promises.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var bluebird = require("bluebird/js/release/promise")();
44
exports.defer = defer;
55
exports.extend = extend;
66
exports.props = props;
7-
exports.promisify = bluebird.promisify;
7+
exports.promisify = promisify;
88
exports.attempt = attempt;
99
exports.forEachSeries = forEachSeries;
1010
exports.toExternalPromise = toExternalPromise;
@@ -24,6 +24,23 @@ exports.nfcall = function(func) {
2424
});
2525
};
2626

27+
function promisify(func) {
28+
return function() {
29+
var args = Array.prototype.slice.call(arguments);
30+
31+
return new Promise(function(resolve, reject) {
32+
args.push(function(error, value) {
33+
if (error) {
34+
reject(error);
35+
} else {
36+
resolve(value);
37+
}
38+
});
39+
func.apply(null, args);
40+
});
41+
};
42+
}
43+
2744
function props(obj) {
2845
// We rely on .keys() and .values() returning properties in the same order.
2946
var keys = Object.keys(obj);

0 commit comments

Comments
 (0)