Skip to content

Commit

Permalink
feat: Upgrade build pipeline to babel 7
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehall314 committed Aug 27, 2019
1 parent b24ca46 commit 07dd174
Show file tree
Hide file tree
Showing 4 changed files with 2,361 additions and 1,268 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["es2015"]
"presets": ["@babel/preset-env"]
}
96 changes: 44 additions & 52 deletions dist/promisify.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.promisify = promisify;
// Symbols is a better way to do this, but not all browsers have good support,
// so instead we'll just make do with a very unlikely string.
var customArgumentsToken = "__ES6-PROMISIFY--CUSTOM-ARGUMENTS__";

/**
* promisify()
* Transforms callback-based function -- func(arg1, arg2 .. argN, callback) -- into
Expand All @@ -16,69 +16,61 @@ var customArgumentsToken = "__ES6-PROMISIFY--CUSTOM-ARGUMENTS__";
* @param {function} original - The function to promisify
* @return {function} A promisified version of `original`
*/

function promisify(original) {
// Ensure the argument is a function
if (typeof original !== "function") {
throw new TypeError("Argument to promisify must be a function");
} // If the user has asked us to decode argument names for them, honour that

// Ensure the argument is a function
if (typeof original !== "function") {
throw new TypeError("Argument to promisify must be a function");
}

// If the user has asked us to decode argument names for them, honour that
var argumentNames = original[customArgumentsToken];
var argumentNames = original[customArgumentsToken]; // If the user has supplied a custom Promise implementation, use it. Otherwise
// fall back to whatever we can find on the global object.

// If the user has supplied a custom Promise implementation, use it. Otherwise
// fall back to whatever we can find on the global object.
var ES6Promise = promisify.Promise || Promise;
var ES6Promise = promisify.Promise || Promise; // If we can find no Promise implemention, then fail now.

// If we can find no Promise implemention, then fail now.
if (typeof ES6Promise !== "function") {
throw new Error("No Promise implementation found; do you need a polyfill?");
}
if (typeof ES6Promise !== "function") {
throw new Error("No Promise implementation found; do you need a polyfill?");
}

return function () {
var _this = this;
return function () {
var _this = this;

for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

return new ES6Promise(function (resolve, reject) {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

// Append the callback bound to the context
args.push(function callback(err) {
return new ES6Promise(function (resolve, reject) {
// Append the callback bound to the context
args.push(function callback(err) {
if (err) {
return reject(err);
}

if (err) {
return reject(err);
}
for (var _len2 = arguments.length, values = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
values[_key2 - 1] = arguments[_key2];
}

for (var _len2 = arguments.length, values = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
values[_key2 - 1] = arguments[_key2];
}
if (values.length === 1 || !argumentNames) {
return resolve(values[0]);
}

if (values.length === 1 || !argumentNames) {
return resolve(values[0]);
}
var o = {};
values.forEach(function (value, index) {
var name = argumentNames[index];

var o = {};
values.forEach(function (value, index) {
var name = argumentNames[index];
if (name) {
o[name] = value;
}
});
if (name) {
o[name] = value;
}
});
resolve(o);
}); // Call the function.

resolve(o);
});
original.call.apply(original, [_this].concat(args));
});
};
} // Attach this symbol to the exported function, so users can use it

// Call the function.
original.call.apply(original, [_this].concat(args));
});
};
}

// Attach this symbol to the exported function, so users can use it
promisify.argumentNames = customArgumentsToken;
promisify.Promise = undefined;

// Export the public API
exports.promisify = promisify;
promisify.Promise = undefined; // Export the public API

0 comments on commit 07dd174

Please sign in to comment.