Code Monkey home page Code Monkey logo

clean-promise's Introduction

clean-promise

Build Status Gemnasium experimental npm

A minimal and clean implement of JavaScript ES6 Promise, which passes all standard test cases.

Features

  • multiple ES6 features are applied: const/let, Class, Symbol, => etc
  • clean, explict and fast
  • both available on back-end and front-end

Installation

> npm install clean-promise --save

Usage

You can use it like this in your own code:

const Promise = require('clean-promise');

Promise.all([Promise.resolve(1), 2, 3]).return(4444)
    .tap(v => {
        console.log('1 ' + v);
    }).tap(v => {
        console.log('2 ' + v);
    }).return(3).tap(v => {
        console.log('2 ' + v);
    });

APIs

  • .then([function(any value) onResolved], [function(any error) onRejected]) -> Promise
  • .catch(function(any error) onRejected) -> Promise
  • .spread(function(any values...) cb, [onRejected]) -> Promise
  • .all(Iterable<any> | Promise<Iterable<any>> input) -> Promise
  • .map(function(any item, int index, int length) mapper, [function(any error) onRejected]) -> Promise
  • .return(Promise<any> | any value) -> Promise
  • .tap([function(any value) onResolved]) -> Promise
  • Promise.resolve(Promise<any> | any value) -> Promise
  • Promise.reject(any error) -> Promise
  • Promise.all(Iterable<any> | Promise<Iterable<any>> input) -> Promise
  • Promise.map(Iterable<any> | Promise<Iterable<any>> input, function(any item, int index, int length) mapper) -> Promise
  • Promise.race(Iterable<any> | Promise<Iterable<any>> input) -> Promise
  • Promise.try(function() fn) -> Promise

Test

> npm test

Join Me

用ES6特性实现一个标准的轻量级Promise

ChangeLog

V 1.1.1 - 2016.08.30

  • simplify and optimize code
  • update README

V 1.1.0 - 2016.08.26

  • fix async bugs in .all & .return
  • add .tap API

V 1.0.0 - 2016.08.26

  • finish all basical functions
  • do some basical tests
  • fix async bugs in Promise.all & Promise.map
  • add .map API

License

MIT

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.