Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-polyfill - npm Package Compare versions

Comparing version 8.2.3 to 8.3.0

src/any.js

49

dist/polyfill.js

@@ -77,2 +77,44 @@ (function (global, factory) {

/**
* @constructor
*/
function AggregateError(errors, message) {
this.name = 'AggregateError', this.errors = errors;
this.message = message || '';
}
AggregateError.prototype = Error.prototype;
function any(arr) {
var P = this;
return new P(function(resolve, reject) {
if (!(arr && typeof arr.length !== 'undefined')) {
return reject(new TypeError('Promise.any accepts an array'));
}
var args = Array.prototype.slice.call(arr);
if (args.length === 0) return reject();
var rejectionReasons = [];
for (var i = 0; i < args.length; i++) {
try {
P.resolve(args[i])
.then(resolve)
.catch(function(error) {
rejectionReasons.push(error);
if (rejectionReasons.length === args.length) {
reject(
new AggregateError(
rejectionReasons,
'All promises were rejected'
)
);
}
});
} catch (ex) {
reject(ex);
}
}
});
}
// Store setTimeout reference so promise-polyfill will be unaffected by

@@ -281,2 +323,4 @@ // other code modifying setTimeout (like sinon.useFakeTimers())

Promise.any = any;
Promise.allSettled = allSettled;

@@ -356,8 +400,11 @@

globalNS.Promise.prototype['finally'] = finallyConstructor;
}
}
if (!globalNS.Promise.allSettled) {
globalNS.Promise.allSettled = allSettled;
}
if (!globalNS.Promise.any) {
globalNS.Promise.any = any;
}
}
})));

2

dist/polyfill.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})}function t(e){return new this(function(t,n){function o(e,n){if(n&&("object"==typeof n||"function"==typeof n)){var f=n.then;if("function"==typeof f)return void f.call(n,function(t){o(e,t)},function(n){r[e]={status:"rejected",reason:n},0==--i&&t(r)})}r[e]={status:"fulfilled",value:n},0==--i&&t(r)}if(!e||"undefined"==typeof e.length)return n(new TypeError(typeof e+" "+e+" is not iterable(cannot read property Symbol(Symbol.iterator))"));var r=Array.prototype.slice.call(e);if(0===r.length)return t([]);for(var i=r.length,f=0;r.length>f;f++)o(f,r[f])})}function n(e){return!(!e||"undefined"==typeof e.length)}function o(){}function r(e){if(!(this instanceof r))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],l(e,this)}function i(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,r._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var o;try{o=n(e._value)}catch(r){return void u(t.promise,r)}f(t.promise,o)}else(1===e._state?f:u)(t.promise,e._value)})):e._deferreds.push(t)}function f(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof r)return e._state=3,e._value=t,void c(e);if("function"==typeof n)return void l(function(e,t){return function(){e.apply(t,arguments)}}(n,t),e)}e._state=1,e._value=t,c(e)}catch(o){u(e,o)}}function u(e,t){e._state=2,e._value=t,c(e)}function c(e){2===e._state&&0===e._deferreds.length&&r._immediateFn(function(){e._handled||r._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;n>t;t++)i(e,e._deferreds[t]);e._deferreds=null}function l(e,t){var n=!1;try{e(function(e){n||(n=!0,f(t,e))},function(e){n||(n=!0,u(t,e))})}catch(o){if(n)return;n=!0,u(t,o)}}var a=setTimeout;r.prototype["catch"]=function(e){return this.then(null,e)},r.prototype.then=function(e,t){var n=new this.constructor(o);return i(this,new function(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}(e,t,n)),n},r.prototype["finally"]=e,r.all=function(e){return new r(function(t,o){function r(e,n){try{if(n&&("object"==typeof n||"function"==typeof n)){var u=n.then;if("function"==typeof u)return void u.call(n,function(t){r(e,t)},o)}i[e]=n,0==--f&&t(i)}catch(c){o(c)}}if(!n(e))return o(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(e);if(0===i.length)return t([]);for(var f=i.length,u=0;i.length>u;u++)r(u,i[u])})},r.allSettled=t,r.resolve=function(e){return e&&"object"==typeof e&&e.constructor===r?e:new r(function(t){t(e)})},r.reject=function(e){return new r(function(t,n){n(e)})},r.race=function(e){return new r(function(t,o){if(!n(e))return o(new TypeError("Promise.race accepts an array"));for(var i=0,f=e.length;f>i;i++)r.resolve(e[i]).then(t,o)})},r._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){a(e,0)},r._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var s=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"function"!=typeof s.Promise?s.Promise=r:(s.Promise.prototype["finally"]||(s.Promise.prototype["finally"]=e),s.Promise.allSettled||(s.Promise.allSettled=t))});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})}function t(e){return new this(function(t,n){function r(e,n){if(n&&("object"==typeof n||"function"==typeof n)){var f=n.then;if("function"==typeof f)return void f.call(n,function(t){r(e,t)},function(n){o[e]={status:"rejected",reason:n},0==--i&&t(o)})}o[e]={status:"fulfilled",value:n},0==--i&&t(o)}if(!e||"undefined"==typeof e.length)return n(new TypeError(typeof e+" "+e+" is not iterable(cannot read property Symbol(Symbol.iterator))"));var o=Array.prototype.slice.call(e);if(0===o.length)return t([]);for(var i=o.length,f=0;o.length>f;f++)r(f,o[f])})}function n(e,t){this.name="AggregateError",this.errors=e,this.message=t||""}function r(e){var t=this;return new t(function(r,o){if(!e||"undefined"==typeof e.length)return o(new TypeError("Promise.any accepts an array"));var i=Array.prototype.slice.call(e);if(0===i.length)return o();for(var f=[],u=0;i.length>u;u++)try{t.resolve(i[u]).then(r)["catch"](function(e){f.push(e),f.length===i.length&&o(new n(f,"All promises were rejected"))})}catch(c){o(c)}})}function o(e){return!(!e||"undefined"==typeof e.length)}function i(){}function f(e){if(!(this instanceof f))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],s(e,this)}function u(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,f._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var r;try{r=n(e._value)}catch(o){return void a(t.promise,o)}c(t.promise,r)}else(1===e._state?c:a)(t.promise,e._value)})):e._deferreds.push(t)}function c(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof f)return e._state=3,e._value=t,void l(e);if("function"==typeof n)return void s(function(e,t){return function(){e.apply(t,arguments)}}(n,t),e)}e._state=1,e._value=t,l(e)}catch(r){a(e,r)}}function a(e,t){e._state=2,e._value=t,l(e)}function l(e){2===e._state&&0===e._deferreds.length&&f._immediateFn(function(){e._handled||f._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;n>t;t++)u(e,e._deferreds[t]);e._deferreds=null}function s(e,t){var n=!1;try{e(function(e){n||(n=!0,c(t,e))},function(e){n||(n=!0,a(t,e))})}catch(r){if(n)return;n=!0,a(t,r)}}n.prototype=Error.prototype;var d=setTimeout;f.prototype["catch"]=function(e){return this.then(null,e)},f.prototype.then=function(e,t){var n=new this.constructor(i);return u(this,new function(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}(e,t,n)),n},f.prototype["finally"]=e,f.all=function(e){return new f(function(t,n){function r(e,o){try{if(o&&("object"==typeof o||"function"==typeof o)){var u=o.then;if("function"==typeof u)return void u.call(o,function(t){r(e,t)},n)}i[e]=o,0==--f&&t(i)}catch(c){n(c)}}if(!o(e))return n(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(e);if(0===i.length)return t([]);for(var f=i.length,u=0;i.length>u;u++)r(u,i[u])})},f.any=r,f.allSettled=t,f.resolve=function(e){return e&&"object"==typeof e&&e.constructor===f?e:new f(function(t){t(e)})},f.reject=function(e){return new f(function(t,n){n(e)})},f.race=function(e){return new f(function(t,n){if(!o(e))return n(new TypeError("Promise.race accepts an array"));for(var r=0,i=e.length;i>r;r++)f.resolve(e[r]).then(t,n)})},f._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){d(e,0)},f._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var p=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"function"!=typeof p.Promise?p.Promise=f:(p.Promise.prototype["finally"]||(p.Promise.prototype["finally"]=e),p.Promise.allSettled||(p.Promise.allSettled=t),p.Promise.any||(p.Promise.any=r))});

@@ -73,2 +73,44 @@ 'use strict';

/**
* @constructor
*/
function AggregateError(errors, message) {
this.name = 'AggregateError', this.errors = errors;
this.message = message || '';
}
AggregateError.prototype = Error.prototype;
function any(arr) {
var P = this;
return new P(function(resolve, reject) {
if (!(arr && typeof arr.length !== 'undefined')) {
return reject(new TypeError('Promise.any accepts an array'));
}
var args = Array.prototype.slice.call(arr);
if (args.length === 0) return reject();
var rejectionReasons = [];
for (var i = 0; i < args.length; i++) {
try {
P.resolve(args[i])
.then(resolve)
.catch(function(error) {
rejectionReasons.push(error);
if (rejectionReasons.length === args.length) {
reject(
new AggregateError(
rejectionReasons,
'All promises were rejected'
)
);
}
});
} catch (ex) {
reject(ex);
}
}
});
}
// Store setTimeout reference so promise-polyfill will be unaffected by

@@ -277,2 +319,4 @@ // other code modifying setTimeout (like sinon.useFakeTimers())

Promise.any = any;
Promise.allSettled = allSettled;

@@ -279,0 +323,0 @@

@@ -73,2 +73,44 @@ 'use strict';

/**
* @constructor
*/
function AggregateError(errors, message) {
this.name = 'AggregateError', this.errors = errors;
this.message = message || '';
}
AggregateError.prototype = Error.prototype;
function any(arr) {
var P = this;
return new P(function(resolve, reject) {
if (!(arr && typeof arr.length !== 'undefined')) {
return reject(new TypeError('Promise.any accepts an array'));
}
var args = Array.prototype.slice.call(arr);
if (args.length === 0) return reject();
var rejectionReasons = [];
for (var i = 0; i < args.length; i++) {
try {
P.resolve(args[i])
.then(resolve)
.catch(function(error) {
rejectionReasons.push(error);
if (rejectionReasons.length === args.length) {
reject(
new AggregateError(
rejectionReasons,
'All promises were rejected'
)
);
}
});
} catch (ex) {
reject(ex);
}
}
});
}
// Store setTimeout reference so promise-polyfill will be unaffected by

@@ -277,2 +319,4 @@ // other code modifying setTimeout (like sinon.useFakeTimers())

Promise.any = any;
Promise.allSettled = allSettled;

@@ -352,6 +396,9 @@

globalNS.Promise.prototype['finally'] = finallyConstructor;
}
}
if (!globalNS.Promise.allSettled) {
globalNS.Promise.allSettled = allSettled;
}
if (!globalNS.Promise.any) {
globalNS.Promise.any = any;
}
}
{
"name": "promise-polyfill",
"version": "8.2.3",
"version": "8.3.0",
"description": "Lightweight promise polyfill. A+ compliant",

@@ -21,2 +21,3 @@ "main": "lib/index.js",

"test": "npm run lint && mocha && karma start --single-run",
"ci-test": "npm run lint && mocha",
"prebuild": "rimraf lib dist",

@@ -47,8 +48,8 @@ "build": "run-p build:**",

"husky": "^0.14.3",
"karma": "^4.1.0",
"karma-browserify": "^6.0.0",
"karma": "^6.3.16",
"karma-browserify": "^8.1.0",
"karma-chrome-launcher": "^0.2.2",
"karma-mocha": "^0.2.1",
"lint-staged": "^5.0.0",
"mocha": "^6.1.4",
"mocha": "^10.1.0",
"npm-run-all": "^4.1.2",

@@ -61,4 +62,4 @@ "prettier": "^1.8.2",

"sinon": "^1.17.2",
"typescript": "^3.5.1",
"watchify": "^3.11.1"
"watchify": "^3.11.1",
"typescript": "^4.6.2"
},

@@ -70,4 +71,3 @@ "keywords": [

"promises-aplus"
],
"dependencies": {}
]
}
import promiseFinally from './finally';
import allSettled from './allSettled';
import any from './any';

@@ -207,2 +208,4 @@ // Store setTimeout reference so promise-polyfill will be unaffected by

Promise.any = any;
Promise.allSettled = allSettled;

@@ -209,0 +212,0 @@

import Promise from './index';
import promiseFinally from './finally';
import allSettled from './allSettled';
import any from './any';

@@ -31,6 +32,9 @@ /** @suppress {undefinedVars} */

globalNS.Promise.prototype['finally'] = promiseFinally;
}
}
if (!globalNS.Promise.allSettled) {
globalNS.Promise.allSettled = allSettled;
}
if (!globalNS.Promise.any) {
globalNS.Promise.any = any;
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc