es6-promisify
Advanced tools
Comparing version 6.1.1 to 7.0.0
@@ -1,76 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
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 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` | ||
*/ | ||
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 () { | ||
var _this = this; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return new ES6Promise(function (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(function (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; // Export the public API | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.promisify=promisify;var customArgumentsToken="__ES6-PROMISIFY--CUSTOM-ARGUMENTS__";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=this,e=arguments.length,f=Array(e),g=0;g<e;g++)f[g]=arguments[g];return new c(function(c,e){f.push(function(a){if(a)return e(a);for(var d=arguments.length,f=Array(1<d?d-1:0),g=1;g<d;g++)f[g-1]=arguments[g];if(1===f.length||!b)return c(f[0]);var h={};f.forEach(function(a,c){var d=b[c];d&&(h[d]=a)}),c(h)}),a.apply(d,f)})}}promisify.argumentNames="__ES6-PROMISIFY--CUSTOM-ARGUMENTS__",promisify.Promise=void 0; |
{ | ||
"name": "es6-promisify", | ||
"version": "6.1.1", | ||
"version": "7.0.0", | ||
"description": "Converts callback-based functions to ES6 Promises", | ||
"main": "dist/promisify.js", | ||
"main": "./dist/promisify.js", | ||
"module": "./dist/promisify.mjs", | ||
"exports": { | ||
"import": "./dist/promisify.mjs", | ||
"require": "./dist/promisify.js" | ||
}, | ||
"author": "Mike Hall <mikehall314@gmail.com>", | ||
"keywords": [ | ||
"promise", | ||
"promises", | ||
"es6", | ||
"promisify" | ||
"promisify", | ||
"es6-promisify" | ||
], | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"prettier": "prettier --write 'lib/**/*.{js,yml}'", | ||
"lint": "eslint 'lib/*.js' 'test/*.js'", | ||
"pretest": "npm run lint && npm run build", | ||
"build": "babel lib -d dist", | ||
"prettier": "prettier --write lib", | ||
"lint": "eslint lib test", | ||
"pretest": "npm run build", | ||
"build:es": "babel lib/promisify.js -o dist/promisify.mjs --config-file ./babel.config-module.js", | ||
"build:cjs": "babel lib/promisify.js -o dist/promisify.js --config-file ./babel.config-nomodule.js", | ||
"build": "npm run build:es && npm run build:cjs", | ||
"test": "tape test", | ||
"test:coverage": "nyc npm test" | ||
}, | ||
"bugs": "http://github.com/digitaldesignlabs/es6-promisify/issues", | ||
"bugs": "http://github.com/mikehall314/es6-promisify/issues", | ||
"files": [ | ||
"dist/promisify.js" | ||
"dist/promisify.js", | ||
"dist/promisify.mjs" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/digitaldesignlabs/es6-promisify.git" | ||
"url": "mikehall314/es6-promisify" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.8.7", | ||
"@babel/preset-env": "^7.8.7", | ||
"@puntt/eslint-config": "0.0.4", | ||
"@babel/cli": "^7.14.3", | ||
"@babel/core": "^7.14.3", | ||
"@babel/preset-env": "^7.14.2", | ||
"babel-preset-minify": "^0.5.1", | ||
"es6-promise": "^4.2.8", | ||
"eslint": "5.16.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^2.0.5", | ||
"sinon": "^9.0.1", | ||
"tape": "^4.13.2" | ||
"eslint": "^7.27.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-config-standard": "^16.0.3", | ||
"eslint-plugin-import": "^2.23.3", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"husky": "^6.0.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.3.0", | ||
"sinon": "^10.0.0", | ||
"tape": "^5.2.2" | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
[![Travis CI](https://travis-ci.org/digitaldesignlabs/es6-promisify.svg)](https://travis-ci.org/digitaldesignlabs/es6-promisify) | ||
![Build Status](https://github.com/digitaldesignlabs/es6-promisify/actions/workflows/test.yml/badge.svg) | ||
# es6-promisify | ||
Converts callback-based functions to ES6/ES2015 Promises, using a boilerplate callback function. | ||
Converts callback-based functions to Promises, using a boilerplate callback function. | ||
@@ -92,9 +92,2 @@ ## Install | ||
### Changes from v5.0.0 | ||
- Allow developer to specify a different implementations of `Promise` | ||
- No longer ships with a polyfill for `Promise`. If your environment has no native `Promise` you must polyfill yourself, or set `promisify.Promise` to an A+ compatible `Promise` implementation. | ||
- Removed support for `settings.thisArg`: use `.bind()` instead. | ||
- Removed support for `settings.multiArgs`: use named arguments instead. | ||
Published under the [MIT License](http://opensource.org/licenses/MIT). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
5
6503
16
7
93
1