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

vow

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vow - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test.js

8

lib/vow.js

@@ -9,3 +9,3 @@ /**

*
* @version 0.1.2
* @version 0.1.3
*/

@@ -202,2 +202,8 @@

resolve : function(val) {
return this.isPromise(val)?
val :
this.when(val);
},
when : function(obj, onFulfilled, onRejected) {

@@ -204,0 +210,0 @@ return (this.isPromise(obj)? obj : new Promise(obj)).then(onFulfilled, onRejected);

2

package.json
{
"name" : "vow",
"version" : "0.1.2",
"version" : "0.1.3",
"description" : "Promises/A+ proposal compatible promises library",

@@ -5,0 +5,0 @@ "homepage" : "https://github.com/dfilatov/jspromise",

@@ -6,1 +6,78 @@ Vow [![Build Status](https://secure.travis-ci.org/dfilatov/jspromise.png)](http://travis-ci.org/dfilatov/jspromise)

See https://github.com/promises-aplus/promises-spec.
Getting Started
---------------
###In the Node.js###
You can install using Node Package Manager (npm):
npm install vow
###In the Browsers###
```html
<script type="text/javascript" src="vow.min.js"></script>
```
Also RequireJS module format supported.
API
---
####Vow.promise()####
Create promise
````javascript
var promise = Vow.promise();
````
###Promise API###
####fulfill(value)####
Fulfill promise with given ````value````
````javascript
promise.fulfill(value);
````
####reject(reason)####
Reject promise with given ````reason````
````javascript
promise.reject(error);
````
####isFulfilled()####
Returns whether the promise is fulfilled
````javascript
promise.isFulfilled();
````
####isRejected()####
Returns whether the promise is rejected
````javascript
promise.isRejected();
````
####isResolved()####
Returns whether the promise is fulfilled or rejected
````javascript
promise.isResolved();
````
####then([onFulfilled], [onRejected])####
Arranges for:
* ````onFulfilled```` to be called with the value after promise is fulfilled,
* ````onRejected```` to be called with the rejection reason after promise is rejected.
Returns a new promise. See [Promises/A+ specification](https://github.com/promises-aplus/promises-spec) for details.
````javascript
promise.then(onFulfilled, onRejected);
````
####fail(onRejected)####
Arranges to call ````onRejected```` on the promise's rejection reason if it is rejected.
####spread([onFulfilled], [onRejected])####
Like "then", but "spreads" the array into a variadic value handler.
###Vow API###
####isPromise(value)####
Returns whether the given ````value```` is a promise.
####fulfill(value)####
Returns a promise that has already been fulfilled with the given ````value````. If ````value```` is a promise, returned promise will be fulfilled with fulfill/rejection value of given promise.
####reject(reasonOrPromise)####
Returns a promise that has already been rejected with the given ````value````. If ````value```` is a promise, returned promise will be rejected with fulfill/rejection value of given promise.
####when(valueOrPromise, [onFulfilled], [onRejected])####
####all(promisesOrValues)####
####allResolved(promisesOrValues)####
####any(promisesOrValues)####
####timeout(promise, timeout)####

@@ -508,2 +508,23 @@ var Vow = require('..');

'Vow.resolve' : {
'resulting promise should be argument if it is promise' : function(test) {
var promise = Vow.promise(),
isFulfilled = promise.isFulfilled(),
resPromise = Vow.resolve(promise);
test.strictEqual(resPromise, promise);
test.strictEqual(resPromise.isFulfilled(), isFulfilled);
test.done();
},
'resulting promise should be fulfilled if argument is non-promise' : function(test) {
var promise = Vow.resolve('val');
promise.then(function(val) {
test.strictEqual(val, 'val');
test.done();
});
}
},
'Vow.when' : {

@@ -510,0 +531,0 @@ 'onFullfilled callback should be called when argument fullfilled' : function(test) {

@@ -9,3 +9,3 @@ /**

*
* @version 0.1.2
*/(function(e){var t=typeof process=="object"?process.nextTick:e.setImmediate?e.setImmediate:e.postMessage?function(){var t=[],n="__promise"+ +(new Date);return e.addEventListener("message",function(r){if(r.source===e&&r.data===n){r.stopPropagation();var i=t,s=0,o=t.length;t=[];while(s<o)i[s++]()}},!0),function(r){t.push(r)===1&&e.postMessage(n,"*")}}():function(e){setTimeout(e,0)},n=function(e){return typeof e=="function"},r=function(e){this._res=e,this._isFulfilled=typeof e!="undefined",this._isRejected=!1,this._fulfilledCallbacks=[],this._rejectedCallbacks=[]};r.prototype={valueOf:function(){return this._res},isFulfilled:function(){return this._isFulfilled},isRejected:function(){return this._isRejected},isResolved:function(){return this._isFulfilled||this._isRejected},fulfill:function(e){if(this.isResolved())return;this._isFulfilled=!0,this._res=e,this._callCallbacks(this._fulfilledCallbacks),this._fulfilledCallbacks=this._rejectedCallbacks=null},reject:function(e){if(this.isResolved())return;this._isRejected=!0,this._res=e,this._callCallbacks(this._rejectedCallbacks),this._fulfilledCallbacks=this._rejectedCallbacks=null},then:function(e,t){var n=new r,i;return this._isRejected||(i={promise:n,fn:e},this._isFulfilled?this._callCallbacks([i]):this._fulfilledCallbacks.push(i)),this._isFulfilled||(i={promise:n,fn:t},this._isRejected?this._callCallbacks([i]):this._rejectedCallbacks.push(i)),n},fail:function(e){return this.then(null,e)},spread:function(e,t){return this.then(function(t){return e.apply(this,t)},t)},_callCallbacks:function(e){if(!e.length)return;var r=this._res,s=this.isFulfilled();t(function(){var t=0,o=e.length,u;while(t<o){var a=(u=e[t++]).promise,f=u.fn;if(n(f)){var l;try{l=f(r)}catch(c){a.reject(c);continue}i.isPromise(l)?function(e){l.then(function(t){e.fulfill(t)},function(t){e.reject(t)})}(a):a.fulfill(l)}else s?a.fulfill(r):a.reject(r)}})}};var i={promise:function(e){return new r(e)},isPromise:function(e){return e&&n(e.then)},fulfill:function(e){return this.when(e,null,function(e){return e})},reject:function(e){return this.when(e,function(e){var t=new r;return t.reject(e),t})},when:function(e,t,n){return(this.isPromise(e)?e:new r(e)).then(t,n)},forEach:function(e,t,n){var r=0,i=e.length;while(r<i)this.when(e[r++],t,n)},all:function(e){var t=new r,n=e.length;if(n){var i=function(){if(!--n){var r=[],i;while(i=e[n++])r.push(i.valueOf());t.fulfill(r)}},s=function(e){t.reject(e)};this.forEach(e,i,s)}else t.fulfill([]);return t},allResolved:function(e){var t=new r,n=e.length;if(n){var i=function(){--n||t.fulfill(e)};this.forEach(e,i,i)}else t.fulfill(e);return t},any:function(e){var t=new r,n=e.length;if(n){var i=0,s,o=function(e){t.fulfill(e)},u=function(e){i||(s=e),++i===n&&t.reject(s)};this.forEach(e,o,u)}else t.reject(Error());return t},timeout:function(e,t){var n=new r,i=setTimeout(function(){n.reject(Error("timed out"))},t);return e.then(function(e){clearTimeout(i),n.fulfill(e)},function(e){clearTimeout(i),n.reject(e)}),n}};typeof exports=="object"?module.exports=i:typeof define=="function"?define(function(e,t,n){n.exports=i}):e.Vow=i})(this);
* @version 0.1.3
*/(function(e){var t=typeof process=="object"?process.nextTick:e.setImmediate?e.setImmediate:e.postMessage?function(){var t=[],n="__promise"+ +(new Date);return e.addEventListener("message",function(r){if(r.source===e&&r.data===n){r.stopPropagation();var i=t,s=0,o=t.length;t=[];while(s<o)i[s++]()}},!0),function(r){t.push(r)===1&&e.postMessage(n,"*")}}():function(e){setTimeout(e,0)},n=function(e){return typeof e=="function"},r=function(e){this._res=e,this._isFulfilled=typeof e!="undefined",this._isRejected=!1,this._fulfilledCallbacks=[],this._rejectedCallbacks=[]};r.prototype={valueOf:function(){return this._res},isFulfilled:function(){return this._isFulfilled},isRejected:function(){return this._isRejected},isResolved:function(){return this._isFulfilled||this._isRejected},fulfill:function(e){if(this.isResolved())return;this._isFulfilled=!0,this._res=e,this._callCallbacks(this._fulfilledCallbacks),this._fulfilledCallbacks=this._rejectedCallbacks=null},reject:function(e){if(this.isResolved())return;this._isRejected=!0,this._res=e,this._callCallbacks(this._rejectedCallbacks),this._fulfilledCallbacks=this._rejectedCallbacks=null},then:function(e,t){var n=new r,i;return this._isRejected||(i={promise:n,fn:e},this._isFulfilled?this._callCallbacks([i]):this._fulfilledCallbacks.push(i)),this._isFulfilled||(i={promise:n,fn:t},this._isRejected?this._callCallbacks([i]):this._rejectedCallbacks.push(i)),n},fail:function(e){return this.then(null,e)},spread:function(e,t){return this.then(function(t){return e.apply(this,t)},t)},_callCallbacks:function(e){if(!e.length)return;var r=this._res,s=this.isFulfilled();t(function(){var t=0,o=e.length,u;while(t<o){var a=(u=e[t++]).promise,f=u.fn;if(n(f)){var l;try{l=f(r)}catch(c){a.reject(c);continue}i.isPromise(l)?function(e){l.then(function(t){e.fulfill(t)},function(t){e.reject(t)})}(a):a.fulfill(l)}else s?a.fulfill(r):a.reject(r)}})}};var i={promise:function(e){return new r(e)},isPromise:function(e){return e&&n(e.then)},fulfill:function(e){return this.when(e,null,function(e){return e})},reject:function(e){return this.when(e,function(e){var t=new r;return t.reject(e),t})},resolve:function(e){return this.isPromise(e)?e:this.when(e)},when:function(e,t,n){return(this.isPromise(e)?e:new r(e)).then(t,n)},forEach:function(e,t,n){var r=0,i=e.length;while(r<i)this.when(e[r++],t,n)},all:function(e){var t=new r,n=e.length;if(n){var i=function(){if(!--n){var r=[],i;while(i=e[n++])r.push(i.valueOf());t.fulfill(r)}},s=function(e){t.reject(e)};this.forEach(e,i,s)}else t.fulfill([]);return t},allResolved:function(e){var t=new r,n=e.length;if(n){var i=function(){--n||t.fulfill(e)};this.forEach(e,i,i)}else t.fulfill(e);return t},any:function(e){var t=new r,n=e.length;if(n){var i=0,s,o=function(e){t.fulfill(e)},u=function(e){i||(s=e),++i===n&&t.reject(s)};this.forEach(e,o,u)}else t.reject(Error());return t},timeout:function(e,t){var n=new r,i=setTimeout(function(){n.reject(Error("timed out"))},t);return e.then(function(e){clearTimeout(i),n.fulfill(e)},function(e){clearTimeout(i),n.reject(e)}),n}};typeof exports=="object"?module.exports=i:typeof define=="function"?define(function(e,t,n){n.exports=i}):e.Vow=i})(this);
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