Skip to content

Commit

Permalink
feat: Minify by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehall314 committed Apr 9, 2021
1 parent 02548b5 commit 647196e
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 143 deletions.
2 changes: 2 additions & 0 deletions babel.config-module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
comments: false,
presets: [
[
"@babel/preset-env",
Expand All @@ -9,5 +10,6 @@ module.exports = {
},
},
],
"minify",
],
};
2 changes: 2 additions & 0 deletions babel.config-nomodule.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
comments: false,
presets: [
[
"@babel/preset-env",
Expand All @@ -10,5 +11,6 @@ module.exports = {
},
},
],
"minify",
],
};
77 changes: 1 addition & 76 deletions dist/promisify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 1 addition & 67 deletions dist/promisify.mjs
Original file line number Diff line number Diff line change
@@ -1,67 +1 @@
// 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 an ES6-compatible Promise. Promisify provides a default callback of the
* form (error, result) and rejects when `error` is truthy.
*
* @param {function} original - The function to promisify
* @return {function} A promisified version of `original`
*/

export 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


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.

var ES6Promise = promisify.Promise || Promise; // 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?");
}

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

return new ES6Promise((resolve, reject) => {
// Append the callback bound to the context
args.push(function callback(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];
}

if (values.length === 1 || !argumentNames) {
return resolve(values[0]);
}

var o = {};
values.forEach((value, index) => {
var name = argumentNames[index];

if (name) {
o[name] = value;
}
});
resolve(o);
}); // Call the function.

original.apply(this, args);
});
};
} // Attach this symbol to the exported function, so users can use it

promisify.argumentNames = customArgumentsToken;
promisify.Promise = undefined;
var customArgumentsToken="__ES6-PROMISIFY--CUSTOM-ARGUMENTS__";export function promisify(a){if("function"!=typeof a)throw new TypeError("Argument to promisify must be a function");var b=a[customArgumentsToken],c=promisify.Promise||Promise;if("function"!=typeof c)throw new Error("No Promise implementation found; do you need a polyfill?");return function(){for(var d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];return new c((c,d)=>{e.push(function(a){if(a)return d(a);for(var e=arguments.length,f=Array(1<e?e-1:0),g=1;g<e;g++)f[g-1]=arguments[g];if(1===f.length||!b)return c(f[0]);var h={};f.forEach((a,c)=>{var d=b[c];d&&(h[d]=a)}),c(h)}),a.apply(this,e)})}}promisify.argumentNames="__ES6-PROMISIFY--CUSTOM-ARGUMENTS__",promisify.Promise=void 0;
Loading

0 comments on commit 647196e

Please sign in to comment.