cranberry v1.2.0
Cranberry
Cranberry is a Promises/A+ implementation written as a lightweight layer on top of Promise with additional features not in the promises/a+ spec. It passes the Promises/A+ Test Suite.
Rationale
If you have a browser baseline that includes most relatively recent browsers you can use Promise without a polyfill. This is great! Promise implementations have additional features that make them useful but the downside is that they can make stacks grow quite long. Cranberry works around this issue by using native promises under the hood.
Installation
npm install cranberryUsage
var Promise = require('cranberry'); //or give it any name you likeAPI
Prototype methods
.then(onFulfilled, onRejected)
See MDN docs
.catch(onRejected)
See MDN docs
.catch(constructor, onRejected)
Like the call above, but it's only run is the rejection value of the promise it's called on is an instance of constructor.
.tap(func)
Only run if called on a fulfilled promise. Returns a new promise (res) whose resolution value is the same as the promise it's called on. If func returns a promise, the resolution of the returned promise is delayed until said promise is settled. If the promise returned by func is rejected (or if func throws), the returned promise is rejected as well, with the same value.
.finally(func)
Like .tap(), but calls func even if run on a rejected promise.
.spread(onFulfilled)
Like then, but if the resolution value of the promise it's called on is an array, the it is used as the arguments array to onFulfilled.
Promise.resolve([1, 2]).spread(function(one, two)){
//one + two === 3
});Constructor methods
Promise.resolve(value)
See MDN docs
Promise.reject(value)
See MDN docs
Promise.all(promises)
See MDN docs