# native-abort-controller

> Returns native AbortController/AbortSignal if available or the abort-controller module if not

Latest version **1.0.4** (published 2021-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install native-abort-controller
pnpm add native-abort-controller
yarn add native-abort-controller
bun add native-abort-controller
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-09-20 |
| First published | 2020-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alex Potsides |
| Maintainers | achingbrain |

## Links

- npm: https://www.npmjs.com/package/native-abort-controller
- Repository: https://github.com/achingbrain/native-abort-controller
- Homepage: https://github.com/achingbrain/native-abort-controller#readme
- Issues: https://github.com/achingbrain/native-abort-controller/issues
- npm.io page: https://npm.io/package/native-abort-controller

## Recent versions

- 1.0.4 (latest) — 2021-09-20
- 1.0.3 — 2021-02-03
- 1.0.2 — 2021-02-03
- 1.0.1 — 2021-02-03
- 1.0.0 — 2021-02-03
- 0.0.3 — 2020-08-28
- 0.0.2 — 2020-08-28
- 0.0.1 — 2020-08-28

## README

# native-abort-controller

> Returns native AbortController/AbortSignal if available or the abort-controller module if not

An (almost) drop-in replacement for the `abort-controller` module that returns the native AbortController if available or the polyfill if not.

### Why?

Some environments such as the Electron Renderer process straddle the node/browser divide with features from both APIs available.  In these cases the webpack approach of always using the `browser` field in your `package.json` to override requires is too heavy-handed as sometimes you want to use the node version of an API.

Instead we can check for the availability of a given API and return it, rather than the node-polyfill for that API.

This module may become unecessary if [mysticatea/abort-controller#24](https://github.com/mysticatea/abort-controller/issues/24) is resolved.

## Install

You must install a version of `abort-controller` [alongside this module](https://docs.npmjs.com/files/package.json#peerdependencies) to be used if a native implementation is not available.

```console
$ npm install --save native-abort-controller abort-controller
```

## Usage

```javascript
import { AbortController } from 'native-abort-controller'

const controller = new AbortController()
const signal = controller.signal

signal.addEventListener('abort', () => {
    console.log('aborted!')
})

controller.abort()
```

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