Coder Social home page Coder Social logo

cranberry's Introduction

Cranberry

Build Status

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 cranberry

Usage

var Promise = require('cranberry'); //or give it any name you like

API

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

License

MIT

cranberry's People

Contributors

codazzo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.