# promise-polyfill

> Lightweight promise polyfill. A+ compliant

Latest version **8.3.0** (published 2023-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-polyfill
pnpm add promise-polyfill
yarn add promise-polyfill
bun add promise-polyfill
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 8.3.0 |
| Published | 2023-01-20 |
| First published | 2014-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/promise-polyfill) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 48.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2142 |
| Author | Taylor Hakes |
| Maintainers | taylorhakes |
| Keywords | promise, promise-polyfill, ES6, promises-aplus |

## Links

- npm: https://www.npmjs.com/package/promise-polyfill
- Repository: https://github.com/taylorhakes/promise-polyfill
- Issues: https://github.com/taylorhakes/promise-polyfill/issues
- npm.io page: https://npm.io/package/promise-polyfill

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 8.3.0 (latest) — 2023-01-20
- 8.0.0 (beta) — 2018-05-06
- 8.2.3 — 2022-03-12
- 8.2.2 — 2022-03-12
- 8.2.1 — 2021-10-22
- 8.2.0 — 2020-10-23
- 8.1.3 — 2019-06-16
- 8.1.2 — 2019-06-15
- 8.1.1 — 2019-06-14
- 8.1.0 — 2018-08-12
- 7.1.2 — 2018-04-05
- 7.1.1 — 2018-03-26
- 7.1.0 — 2018-02-07
- 7.0.2 — 2018-01-25
- 7.0.1 — 2018-01-25
- … 31 more at https://npm.io/package/promise-polyfill/versions

## README

# Promise Polyfill

Lightweight ES6 Promise polyfill for the browser and node. Adheres closely to
the spec. It is a perfect polyfill IE or any other browser that does
not support native promises.

For API information about Promises, please check out this article
[HTML5Rocks article](http://www.html5rocks.com/en/tutorials/es6/promises/).

It is extremely lightweight. **_< 1kb Gzipped_**

## Browser Support

IE8+, Chrome, Firefox, IOS 4+, Safari 5+, Opera

### NPM Use

```
npm install promise-polyfill --save-exact
```

### Bower Use

```
bower install promise-polyfill
```

### CDN Polyfill Use

This will set a global Promise object if the browser doesn't already have `window.Promise`.

```html
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
```

## Downloads

* [Promise](https://raw.github.com/taylorhakes/promise-polyfill/master/dist/polyfill.js)
* [Promise-min](https://raw.github.com/taylorhakes/promise-polyfill/master/dist/polyfill.min.js)

## Simple use

If you would like to add a global Promise object (Node or Browser) if native Promise doesn't exist (polyfill Promise). Use the method below. This is useful if you are building a website and want to support older browsers.
Javascript library authors should _NOT_ use this method.

```js
import 'promise-polyfill/src/polyfill';
```

If you would like to not affect the global environment (sometimes known as a [ponyfill](https://github.com/sindresorhus/ponyfill), you can import the base module. This is nice for library authors or people working in environment where you don't want
to affect the global environment.

```js
import Promise from 'promise-polyfill';
```

If using `require` with Webpack 2+ (rare), you need to specify the default import

```js
var Promise = require('promise-polyfill').default;
```

then you can use like normal Promises

```js
var prom = new Promise(function(resolve, reject) {
  // do a thing, possibly async, then…

  if (/* everything turned out fine */) {
    resolve("Stuff worked!");
  }  else {
    reject(new Error("It broke"));
  }
});

prom.then(function(result) {
  // Do something when async done
});
```

## Performance

By default promise-polyfill uses `setImmediate`, but falls back to `setTimeout`
for executing asynchronously. If a browser does not support `setImmediate`
(IE/Edge are the only browsers with setImmediate), you may see performance
issues. Use a `setImmediate` polyfill to fix this issue.
[setAsap](https://github.com/taylorhakes/setAsap) or
[setImmediate](https://github.com/YuzuJS/setImmediate) work well.

If you polyfill `window.setImmediate` or use `Promise._immediateFn = yourImmediateFn` it will be used instead of `window.setTimeout`

```
npm install setasap --save
```

```js
import Promise from 'promise-polyfill/src/polyfill';
import setAsap from 'setasap';
Promise._immediateFn = setAsap;
```

## Unhandled Rejections

promise-polyfill will warn you about possibly unhandled rejections. It will show
a console warning if a Promise is rejected, but no `.catch` is used. You can
change this behavior by doing.

-**NOTE: This only works on promise-polyfill Promises. Native Promises do not support this function**

```js
Promise._unhandledRejectionFn = <your reject error handler>;
```

If you would like to disable unhandled rejection messages. Use a noop like
below.

```js
Promise._unhandledRejectionFn = function(rejectError) {};
```

## Testing

```
npm install
npm test
```

## License

MIT

---
_Source: https://npm.io/package/promise-polyfill · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
