Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rtsao/browser-unhandled-rejection
A ponyfill/polyfill for browser Promise unhandledrejection events
https://github.com/rtsao/browser-unhandled-rejection
polyfill ponyfill promise unhandled-rejection unhandledrejection
Last synced: 27 days ago
JSON representation
A ponyfill/polyfill for browser Promise unhandledrejection events
- Host: GitHub
- URL: https://github.com/rtsao/browser-unhandled-rejection
- Owner: rtsao
- License: mit
- Created: 2017-04-11T23:58:41.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-29T00:35:23.000Z (almost 7 years ago)
- Last Synced: 2024-12-16T20:03:50.466Z (about 1 month ago)
- Topics: polyfill, ponyfill, promise, unhandled-rejection, unhandledrejection
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 28
- Watchers: 5
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# browser-unhandled-rejection
[![build status][build-badge]][build-href]
[![dependencies status][deps-badge]][deps-href]
[![npm version][npm-badge]][npm-href]A ponyfill/polyfill for browser Promise [`unhandledrejection`](https://developer.mozilla.org/en-US/docs/Web/Events/unhandledrejection) events.
See: https://www.chromestatus.com/features/4805872211460096
[![sauce labs test status][sauce-badge]][sauce-href]
## Install
```bash
npm i browser-unhandled-rejection
```
or
```bash
yarn add browser-unhandled-rejection
```## Usage
### Automatic polyfill
This automatically applies the polyfill to the global `Promise` object if it is needed.
```js
import {auto} from 'browser-unhandled-rejection';auto(); // Applies polyfill if necessary to window.Promise
```### Manual polyfill
The following snippet is equivalent to `auto()`:
```js
import {polyfill} from 'browser-unhandled-rejection';if (typeof PromiseRejectionEvent !== 'undefined') {
polyfill(); // Polyfills window.Promise
}
```### Ponyfill
This may may useful if you don't want to mutate `window.Promise`:
```js
import MyPromise from 'browser-unhandled-rejection';window.addEventListener('unhandledrejection', () => {
console.log('unhandledrejection was triggered');
});MyPromise.reject('will trigger unhandledrejection event');
new MyPromise((resolve, reject) => {
reject('will also trigger unhandledrejection event');
});
```[npm-badge]: https://badge.fury.io/js/browser-unhandled-rejection.svg
[npm-href]: https://www.npmjs.com/package/browser-unhandled-rejection
[build-badge]: https://travis-ci.org/rtsao/browser-unhandled-rejection.svg?branch=master
[build-href]: https://travis-ci.org/rtsao/browser-unhandled-rejection
[deps-badge]: https://img.shields.io/badge/dependencies-none-brightgreen.svg
[deps-href]: https://david-dm.org/rtsao/browser-unhandled-rejection
[sauce-badge]: https://saucelabs.com/browser-matrix/browser-unhandled-rejection.svg
[sauce-href]: https://saucelabs.com/u/browser-unhandled-rejection