<commit_before># AbortController polyfill for abortable fetch()

[![npm version](https://badge.fury.io/js/abortcontroller-polyfill.svg)](https://badge.fury.io/js/abortcontroller-polyfill)

Minimal stubs so that the AbortController DOM API for terminating ```fetch()``` requests can be used
in browsers that doesn't yet implement it. This "polyfill" doesn't actually close the connection
when the request is aborted, but it will call ```.catch()``` with ```err.name == 'AbortError'```
instead of ```.then()```.

```js
const controller = new AbortController();
const signal = controller.signal;
fetch('/some/url', {signal}).then(res => res.json()).then(data => {
  // do something with "data"
}).catch(err => {
  if (err.name == 'AbortError') {
    return;
  }
});
// controller.abort(); // can be called at any time
```

You can read about the [AbortController](https://dom.spec.whatwg.org/#aborting-ongoing-activities) API in the DOM specification.

# How to use

```shell
$ npm install --save abortcontroller-polyfill
```

If you're using webpack or similar, you then import it early in your client entrypoint .js file using

```js
import 'abortcontroller-polyfill'
```

or

```js
require('abortcontroller-polyfill')
```

## Using it along with 'create-react-app'

create-react-app enforces the no-undef eslint rule at compile time so if your
version of eslint does not list ```AbortController``` etc as a known global for
the ```browser``` environment, then you might run into an compile error like:

```
  'AbortController' is not defined  no-undef
```

This can be worked around by (temporarily, details [here](https://github.com/mo/abortcontroller-polyfill/issues/10)) adding a declaration like:

```js
  const AbortController = window.AbortController;
```

# Using it on Node.js

```js
const { AbortController, abortableFetch } = require('abortcontroller-polyfill/dist/abortcontroller');
const { fetch } = abortableFetch(require('node-fetch'));
// or
// import AbortController, { abortableFetch } from 'abortcontroller-polyfill/dist/abortcontroller';
// import _fetch from 'node-fetch';
// const { fetch } = abortableFetch(_fetch);
```
or if you're lazy
```js
global.fetch = require('node-fetch');
require('abortcontroller-polyfill');
```

# Contributors
* [<NAME>](https://github.com/mo)
* [<NAME>](https://github.com/jimmywarting)
* [silverwind](https://github.com/silverwind)
* [<NAME>](https://github.com/rmja)
* [<NAME>](https://github.com/joaovieira)
* [<NAME>](https://github.com/caub)

# License

MIT
<commit_msg>Document how to patch Request class when using node-fetch<commit_after># AbortController polyfill for abortable fetch()

[![npm version](https://badge.fury.io/js/abortcontroller-polyfill.svg)](https://badge.fury.io/js/abortcontroller-polyfill)

Minimal stubs so that the AbortController DOM API for terminating ```fetch()``` requests can be used
in browsers that doesn't yet implement it. This "polyfill" doesn't actually close the connection
when the request is aborted, but it will call ```.catch()``` with ```err.name == 'AbortError'```
instead of ```.then()```.

```js
const controller = new AbortController();
const signal = controller.signal;
fetch('/some/url', {signal}).then(res => res.json()).then(data => {
  // do something with "data"
}).catch(err => {
  if (err.name == 'AbortError') {
    return;
  }
});
// controller.abort(); // can be called at any time
```

You can read about the [AbortController](https://dom.spec.whatwg.org/#aborting-ongoing-activities) API in the DOM specification.

# How to use

```shell
$ npm install --save abortcontroller-polyfill
```

If you're using webpack or similar, you then import it early in your client entrypoint .js file using

```js
import 'abortcontroller-polyfill'
```

or

```js
require('abortcontroller-polyfill')
```

## Using it along with 'create-react-app'

create-react-app enforces the no-undef eslint rule at compile time so if your
version of eslint does not list ```AbortController``` etc as a known global for
the ```browser``` environment, then you might run into an compile error like:

```
  'AbortController' is not defined  no-undef
```

This can be worked around by (temporarily, details [here](https://github.com/mo/abortcontroller-polyfill/issues/10)) adding a declaration like:

```js
  const AbortController = window.AbortController;
```

# Using it on Node.js

```js
const { AbortController, abortableFetch } = require('abortcontroller-polyfill/dist/abortcontroller');
const { fetch } = abortableFetch(require('node-fetch'));
// or
// import AbortController, { abortableFetch } from 'abortcontroller-polyfill/dist/abortcontroller';
// import _fetch from 'node-fetch';
// const { fetch } = abortableFetch(_fetch);
```
or if you're lazy
```js
global.fetch = require('node-fetch');
require('abortcontroller-polyfill');
```

If you also need a ```Request``` class with support for aborting you can do:

```js
const { AbortController, abortableFetch } = require('abortcontroller-polyfill/dist/abortcontroller');
const _nodeFetch = require('node-fetch');
const { fetch, Request } = abortableFetch({fetch: _nodeFetch, Request: _nodeFetch.Request});

const controller = new AbortController();
const signal = controller.signal;
controller.abort();
fetch(Request("http://api.github.com", {signal}))
  .then(r => r.json())
  .then(j => console.log(j))
  .catch(err => {
      if (err.name === 'AbortError') {
          console.log('aborted');
      }
  })
```

# Contributors
* [<NAME>](https://github.com/mo)
* [<NAME>](https://github.com/jimmywarting)
* [silverwind](https://github.com/silverwind)
* [<NAME>](https://github.com/rmja)
* [<NAME>](https://github.com/joaovieira)
* [<NAME>](https://github.com/caub)

# License

MIT

{'fraction_non_alphanumeric': 0.15924567836563647, 'fraction_numerical': 0.0006984459577440195, 'mean_word_length': 4.850868232890705, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, 'https://': 20, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '551637', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1763, 'n_words': 514}