New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

p-promise

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-promise - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

extra/asap.js

58

p.js

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

/*!
* Copyright 2013 Robert Katić
* Released under the MIT license
* https://github.com/rkatic/p/blob/master/LICENSE
*/
;(function( factory ){

@@ -27,4 +32,4 @@ // CommonJS

toStr = ({}).toString,
isArray;
call = ot.call,
apply = ot.apply;

@@ -109,5 +114,2 @@ function onTick() {

isArray = Array.isArray || function( val ) {
return !!val && toStr.call( val ) === "[object Array]";
};

@@ -174,3 +176,6 @@ function forEach( arr, cb ) {

if ( x instanceof Promise ) {
if ( x._state ) {
if ( x === p ) {
Settle( p, REJECTED, new TypeError("You can't resolve a promise with itself") );
} else if ( x._state ) {
Settle( p, x._state, x._value );

@@ -189,2 +194,4 @@

runLater(function() {
var r = resolverFor( p, x );
try {

@@ -194,4 +201,3 @@ var then = x.then;

if ( typeof then === "function" ) {
var r = resolverFor( p, x );
then.call( x, r.resolve, r.reject );
call.call( then, x, r.resolve, r.reject );

@@ -203,3 +209,3 @@ } else {

} catch ( e ) {
Settle( p, REJECTED, e );
r.reject( e );
}

@@ -304,3 +310,3 @@ });

return all( array, [] ).then(function( values ) {
return cb.apply( void 0, values );
return apply.call( cb, void 0, values );
}, eb);

@@ -351,10 +357,8 @@ }, eb);

function valuesHandler( f ) {
function onFulfilled( values ) {
return f( values, [] );
}
function handleValues( values ) {
// Arrays are never considered thenables here, which isn't ideal,
// but I prefer to speed up instead of supporting such silly cases.
return isArray( values ) ?
f( values, [] ) :
P( values ).then(function( values ) {
return f( values, [] );
});
return P( values ).then( onFulfilled );
}

@@ -369,3 +373,3 @@

var waiting = 0;
var outputPromise = new Promise();
var promise = new Promise();
forEach( input, function( x, index ) {

@@ -378,3 +382,3 @@ var p = P( x );

if ( --waiting === 0 ) {
Settle( outputPromise, FULFILLED, output );
Settle( promise, FULFILLED, output );
}

@@ -387,5 +391,5 @@ });

if ( waiting === 0 ) {
Settle( outputPromise, FULFILLED, output );
Settle( promise, FULFILLED, output );
}
return outputPromise;
return promise;
}

@@ -418,2 +422,14 @@

P.promised = promised;
function promised( f ) {
function onFulfilled( thisAndArgs ) {
return apply.apply( f, thisAndArgs );
}
return function() {
var allArgs = all( arguments, [] );
return all( [this, allArgs], [] ).then( onFulfilled );
};
}
P.onerror = null;

@@ -420,0 +436,0 @@

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

(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{P=e()}})(function(){"use strict";var e={f:null,n:null},t=e,n=false,r,i,o=c(typeof window)&&window||c(typeof worker)&&worker,u={}.toString,f;function a(){while(e.n){e=e.n;var t=e.f;e.f=null;t()}n=false}var s=function(e){t=t.n={f:e,n:null};if(!n){n=true;i(a,0)}};function c(e){return e==="object"||e==="function"}function l(e){return e==="function"}if(c(typeof process)&&process&&process.nextTick){i=process.nextTick}else if(l(typeof setImmediate)){i=o?function(e){o.setImmediate(e)}:function(e){setImmediate(e)}}else if(l(typeof MessageChannel)){r=new MessageChannel;r.port1.onmessage=a;i=function(){r.port2.postMessage(0)}}else{i=setTimeout;if(o&&c(typeof Image)&&Image){(function(){var e=0;var t=function(e){var t=new Image;t.onerror=e;t.src="data:image/png,"};try{t(function(){if(--e===0){i=t}});++e}catch(n){}e&&setTimeout(function(){e=0},0)})()}}f=Array.isArray||function(e){return!!e&&u.call(e)==="[object Array]"};function p(e,t){for(var n=0,r=e.length;n<r;++n){if(n in e){t(e[n],n)}}}function v(e){try{if(y.onerror){y.onerror(e)}else{throw e}}catch(t){setTimeout(function(){throw t},0)}}var h=0;var d=1;var _=2;function y(e){return e instanceof I?e:g(new I,e)}function m(e,t,n){if(e._state){return e}e._state=t;e._value=n;if(e._pending.length>0){p(e._pending,s)}e._pending=null;return e}function w(e,t){e._pending.push(t)}function g(e,t){if(e._state){return e}if(t instanceof I){if(t._state){m(e,t._state,t._value)}else{w(t,function(){m(e,t._state,t._value)})}}else if(t!==Object(t)){m(e,d,t)}else{s(function(){try{var n=t.then;if(typeof n==="function"){var r=T(e,t);n.call(t,r.resolve,r.reject)}else{m(e,d,t)}}catch(i){m(e,_,i)}})}return e}function T(e,t){var n=false;return{promise:e,resolve:function(r){if(!n){n=true;if(t&&t===r){m(e,d,r)}else{g(e,r)}}},reject:function(t){if(!n){n=true;m(e,_,t)}}}}y.defer=j;function j(){return T(new I)}function I(){this._state=0;this._value=void 0;this._pending=[]}I.prototype.then=function(e,t){var n=typeof e==="function"?e:null;var r=typeof t==="function"?t:null;var i=this;var o=new I;function u(){var e,t=i._state===d?n:r;if(t!==null){try{e=t(i._value)}catch(u){m(o,_,u);return}g(o,e)}else{m(o,i._state,i._value)}}if(i._state===h){w(i,u)}else{s(u)}return o};I.prototype.done=function(e,t){var n=this;if(e||t){n=n.then(e,t)}n.then(null,v)};I.prototype.fail=function(e){return this.then(null,e)};I.prototype.spread=function(e,t){return this.then(e&&function(n){return b(n,[]).then(function(t){return e.apply(void 0,t)},t)},t)};I.prototype.timeout=function(e,t){var n=this;var r=new I;if(n._state!==h){m(r,n._state,n._value)}else{var i=setTimeout(function(){m(r,_,new Error(t||"Timed out after "+e+" ms"))},e);w(n,function(){clearTimeout(i);m(r,n._state,n._value)})}return r};I.prototype.delay=function(e){var t=this;var n=new I;setTimeout(function(){g(n,t)},e);return n};I.prototype.inspect=function(){switch(this._state){case h:return{state:"pending"};case d:return{state:"fulfilled",value:this._value};case _:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};function k(e){function t(t){return f(t)?e(t,[]):y(t).then(function(t){return e(t,[])})}t._=e;return t}y.allSettled=k(x);function x(e,t){var n=0;var r=new I;p(e,function(e,i){var o=y(e);if(o._state===h){++n;w(o,function(){t[i]=o.inspect();if(--n===0){m(r,d,t)}})}else{t[i]=o.inspect()}});if(n===0){m(r,d,t)}return r}y.all=k(b);function b(e,t){var n=0;var r=j();p(e,function(e,i){var o=y(e);if(o._state===d){t[i]=o._value}else{++n;o.then(function(e){t[i]=e;if(--n===0){r.resolve(t)}},r.reject)}});if(n===0){r.resolve(t)}return r.promise}y.onerror=null;y.nextTick=function(e){s(function(){try{e()}catch(t){setTimeout(function(){throw t},0)}})};return y});
(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{P=e()}})(function(){"use strict";var e={f:null,n:null},t=e,n=false,r,i,o=c(typeof window)&&window||c(typeof worker)&&worker,u=c.call,f=c.apply;function a(){while(e.n){e=e.n;var t=e.f;e.f=null;t()}n=false}var s=function(e){t=t.n={f:e,n:null};if(!n){n=true;i(a,0)}};function c(e){return e==="object"||e==="function"}function l(e){return e==="function"}if(c(typeof process)&&process&&process.nextTick){i=process.nextTick}else if(l(typeof setImmediate)){i=o?function(e){o.setImmediate(e)}:function(e){setImmediate(e)}}else if(l(typeof MessageChannel)){r=new MessageChannel;r.port1.onmessage=a;i=function(){r.port2.postMessage(0)}}else{i=setTimeout;if(o&&c(typeof Image)&&Image){(function(){var e=0;var t=function(e){var t=new Image;t.onerror=e;t.src="data:image/png,"};try{t(function(){if(--e===0){i=t}});++e}catch(n){}e&&setTimeout(function(){e=0},0)})()}}function p(e,t){for(var n=0,r=e.length;n<r;++n){if(n in e){t(e[n],n)}}}function v(e){try{if(m.onerror){m.onerror(e)}else{throw e}}catch(t){setTimeout(function(){throw t},0)}}var h=0;var d=1;var _=2;function m(e){return e instanceof I?e:g(new I,e)}function y(e,t,n){if(e._state){return e}e._state=t;e._value=n;if(e._pending.length>0){p(e._pending,s)}e._pending=null;return e}function w(e,t){e._pending.push(t)}function g(e,t){if(e._state){return e}if(t instanceof I){if(t===e){y(e,_,new TypeError("You can't resolve a promise with itself"))}else if(t._state){y(e,t._state,t._value)}else{w(t,function(){y(e,t._state,t._value)})}}else if(t!==Object(t)){y(e,d,t)}else{s(function(){var n=T(e,t);try{var r=t.then;if(typeof r==="function"){u.call(r,t,n.resolve,n.reject)}else{y(e,d,t)}}catch(i){n.reject(i)}})}return e}function T(e,t){var n=false;return{promise:e,resolve:function(r){if(!n){n=true;if(t&&t===r){y(e,d,r)}else{g(e,r)}}},reject:function(t){if(!n){n=true;y(e,_,t)}}}}m.defer=j;function j(){return T(new I)}function I(){this._state=0;this._value=void 0;this._pending=[]}I.prototype.then=function(e,t){var n=typeof e==="function"?e:null;var r=typeof t==="function"?t:null;var i=this;var o=new I;function u(){var e,t=i._state===d?n:r;if(t!==null){try{e=t(i._value)}catch(u){y(o,_,u);return}g(o,e)}else{y(o,i._state,i._value)}}if(i._state===h){w(i,u)}else{s(u)}return o};I.prototype.done=function(e,t){var n=this;if(e||t){n=n.then(e,t)}n.then(null,v)};I.prototype.fail=function(e){return this.then(null,e)};I.prototype.spread=function(e,t){return this.then(e&&function(n){return E(n,[]).then(function(t){return f.call(e,void 0,t)},t)},t)};I.prototype.timeout=function(e,t){var n=this;var r=new I;if(n._state!==h){y(r,n._state,n._value)}else{var i=setTimeout(function(){y(r,_,new Error(t||"Timed out after "+e+" ms"))},e);w(n,function(){clearTimeout(i);y(r,n._state,n._value)})}return r};I.prototype.delay=function(e){var t=this;var n=new I;setTimeout(function(){g(n,t)},e);return n};I.prototype.inspect=function(){switch(this._state){case h:return{state:"pending"};case d:return{state:"fulfilled",value:this._value};case _:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};function k(e){function t(t){return e(t,[])}function n(e){return m(e).then(t)}n._=e;return n}m.allSettled=k(x);function x(e,t){var n=0;var r=new I;p(e,function(e,i){var o=m(e);if(o._state===h){++n;w(o,function(){t[i]=o.inspect();if(--n===0){y(r,d,t)}})}else{t[i]=o.inspect()}});if(n===0){y(r,d,t)}return r}m.all=k(E);function E(e,t){var n=0;var r=j();p(e,function(e,i){var o=m(e);if(o._state===d){t[i]=o._value}else{++n;o.then(function(e){t[i]=e;if(--n===0){r.resolve(t)}},r.reject)}});if(n===0){r.resolve(t)}return r.promise}m.promised=M;function M(e){function t(t){return f.apply(e,t)}return function(){var e=E(arguments,[]);return E([this,e],[]).then(t)}}m.onerror=null;m.nextTick=function(e){s(function(){try{e()}catch(t){setTimeout(function(){throw t},0)}})};return m});
{
"name": "p-promise",
"version": "0.2.2",
"version": "0.2.3",
"description": "A simple Promises/A+ library.",

@@ -17,9 +17,16 @@ "author": "Robert Katić <robert.katic@gmail.com> (https://github.com/rkatic)",

"posttest": "uglifyjs p.js -o p.min.js -m",
"test": "promises-aplus-tests test/adapter"
"test-own": "mocha -R spec -s 100 test/test.js",
"test-aplus": "promises-aplus-tests test/adapter",
"test": "promises-aplus-tests test/adapter --reporter dot && mocha -s 200 test/test.js"
},
"keywords": [
"promise",
"promises"
"promises",
"promises-aplus",
"browser",
"node"
],
"devDependencies": {
"mocha": "1.x.x",
"expect.js" : "0.2.x",
"promises-aplus-tests": "~1",

@@ -26,0 +33,0 @@ "uglify-js": "~2"

@@ -17,3 +17,3 @@ [![Build Status](https://travis-ci.org/rkatic/p.png?branch=master)](https://travis-ci.org/rkatic/p)

- Simple.
- [Ultra Fast](http://jsperf.com/wqfwewefewrw/3).
- [Ultra Fast](http://jsperf.com/wqfwewefewrw/9).

@@ -20,0 +20,0 @@ ##API

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