Nativebird
π¦ Bluebird alternative within ~200 loc
Install / Use
/learn @doodlewind/NativebirdREADME
NativeBird
Ultralight promise extension compatible with Bluebird
<a href="./package.json"> <img src="https://img.shields.io/npm/v/nativebird.svg?maxAge=300&color=f4e335"/> </a> <a href="./package.json"> <img src="https://img.shields.io/bundlephobia/min/nativebird"/> </a> <a href="./package.json"> <!-- NOTE after "npm run coverage", check whether next line of code formatted correctly --> <img src="https://img.shields.io/badge/Coverage-100%25-83A603.svg?prefix="> </a>
Introduction
As a pioneer in JavaScript async ecosystem, Bluebird is a great userland promise library with handy utility methods included. However the way it works leads to larger bundle size and more verbose stack trace.
NativeBird is compatible with a core Bluebird subset by extending native promise, and all of its extended APIs (implemented within ~200 lines) are fully tested with the corresponding test cases in Bluebird.
NativeBird can be used in several scenarios:
- To reuse promise utility methods like
Promise.mapandPromise.eachwithout copying snippets from a gist. - To perform migration in existing Bluebird projects.
- To simply learn JavaScript async operation skills πΆ.
Installation
npm install nativebird
import Promise from "nativebird";
It's also fine to copy promise.mjs and its type definition directly into your project directory.
API
- Static methods:
Promise.delayPromise.tryPromise.eachPromise.mapSeriesPromise.mapPromise.reducePromise.defer(deprecated)
- Instance methods:
Since NativeBird inherits from native promise, all promise APIs defined in ECMAScript standard (say Promise.allSettled and Promise.any) are naturally supported.
Caveats
Promise.cancelis not supported.- Synchronous inspection (e.g.
Promise.isFulfilled) is not supported.
Contribution
To implement a new API in Bluebird, please also port the corresponding test cases under test/mocha in Bluebird repo and test it with npm test.
License
MIT
