1. es6-promise-polyfill
Polyfill for ES6 Promise
es6-promise-polyfill
Package: es6-promise-polyfill
Created by: lahmatiy
Last modified: Fri, 17 Jun 2022 17:01:03 GMT
Version: 1.2.0
License: MIT
Downloads: 150,267
Repository: https://github.com/lahmatiy/es6-promise-polyfill

Install

npm install es6-promise-polyfill
yarn add es6-promise-polyfill

NPM version
Build Status

ES6 Promise polyfill

This is a polyfill of ES6 Promise. The implementation based on Jake Archibald implementation a subset of rsvp.js. If you're wanting extra features and more debugging options, check out the full library.

For API details and how to use promises, see the JavaScript Promises HTML5Rocks article.

Notes

The main target: implementation should be conformance with browser's implementations and to be minimal as possible in size. So it's strictly polyfill of ES6 Promise specification and nothing more.

It passes both Promises/A+ test suite and rsvp.js test suite. And as small as 2,6KB min (or 1KB min+gzip).

The polyfill uses setImmediate if available, or fallback to use setTimeout. Use setImmediate polyfill by @YuzuJS to reach better performance.

How to use

Browser

To install:

 bower install es6-promise-polyfill

To use:

<script src="bower_components/es6-promise-polyfill/promise.min.js"></script>
<script>
  var promise = new Promise(...);
</script>

Node.js

To install:

 npm install es6-promise-polyfill

To use:

 var Promise = require('es6-promise-polyfill').Promise;
var promise = new Promise(...);

Usage in IE<9

catch is a reserved word in IE<9, meaning promise.catch(func) throws a syntax error. To work around this, use a string to access the property:

 promise['catch'](function(err) {
  // ...
});

Or use .then instead:

 promise.then(undefined, function(err) {
  // ...
});

License

Licensed under the MIT License.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code