Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional ReadableStream polyfill #12

Merged
merged 12 commits into from Feb 14, 2020
6 changes: 6 additions & 0 deletions index.js
Expand Up @@ -22,4 +22,10 @@ if (!global.AbortController) {
global.AbortController = AbortController;
}

if (!global.ReadableStream) {
try {
global.ReadableStream = require('web-streams-polyfill/ponyfill/es2018');
} catch (_) {}
}

module.exports = require('ky/umd');
8 changes: 7 additions & 1 deletion package.json
Expand Up @@ -62,7 +62,13 @@
"xo": "^0.25.3"
},
"peerDependencies": {
"ky": ">=0.17.0"
"ky": ">=0.17.0",
"web-streams-polyfill": ">=2.0.0"
},
"peerDependenciesMeta": {
"web-streams-polyfill": {
"optional": true
}
},
"browser": "browser.js",
"ava": {
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Expand Up @@ -23,6 +23,22 @@ $ npm install ky ky-universal

*Note that you also need to install `ky`.*

For `ReadableStream` support, also install [`web-streams-polyfill`](https://github.com/MattiasBuelens/web-streams-polyfill).
Richienb marked this conversation as resolved.
Show resolved Hide resolved

You can then use it normally:

```js
const ky = require("ky-universal")
Richienb marked this conversation as resolved.
Show resolved Hide resolved

(async () => {
const {body} = ky('https://httpbin.org/bytes/16');
const {value} = await body.getReader().read();
const result = new TextDecoder("utf-8").decode(value)
Richienb marked this conversation as resolved.
Show resolved Hide resolved

// …
})();
```
Richienb marked this conversation as resolved.
Show resolved Hide resolved

## Usage

```js
Expand Down