Gathering detailed insights and metrics for @nichoth/ky-universal
Gathering detailed insights and metrics for @nichoth/ky-universal
Gathering detailed insights and metrics for @nichoth/ky-universal
Gathering detailed insights and metrics for @nichoth/ky-universal
npm install @nichoth/ky-universal
Typescript
Module System
Min. Node Version
Node Version
NPM Version
63.1
Supply Chain
95.7
Quality
74.8
Maintenance
100
Vulnerability
100
License
Total Downloads
374
Last Day
1
Last Week
5
Last Month
13
Last Year
94
Minified
Minified + Gzipped
Latest Version
0.12.1
Package Id
@nichoth/ky-universal@0.12.1
Unpacked Size
6.60 kB
Size
3.07 kB
File Count
7
NPM Version
10.2.3
Node Version
21.2.0
Published on
Jan 04, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
25%
5
Compared to previous week
Last Month
160%
13
Compared to previous month
Last Year
-66.4%
94
Compared to previous year
Use Ky in both Node.js and browsers
As of Ky 1.0.0, it runs natively on Node.js. So this package is no longer needed.
Ky is made for browsers, but this package makes it possible to use it in Node.js too, by polyfilling most of the required browser APIs using node-fetch
.
This package can be useful for:
Note: Before opening an issue, make sure it's an issue with Ky and not its polyfills. Generally, if something works in the browser, but not in Node.js, it's an issue with node-fetch
.
Keep in mind that Ky targets modern browsers when used in the browser. For older browsers, you will need to transpile and use a fetch
polyfill.
This is a fork of sindresorhus/ky-universal. I have changed it so that it does not use top level await
, for compatibility reasons with lambda functions.
1npm install ky ky-universal
Note that you also need to install ky
.
1import ky from 'ky-universal'; 2 3const parsed = await ky('https://httpbin.org/json').json(); 4 5// …
ReadableStream
supportFor ReadableStream
support, also install web-streams-polyfill
:
$ npm install web-streams-polyfill
You can then use it normally:
1import ky from 'ky-universal'; 2 3const {body} = await ky('https://httpbin.org/bytes/16'); 4const {value} = await body.getReader().read(); 5const result = new TextDecoder('utf-8').decode(value); 6 7// …
The API is exactly the same as the Ky API, including the named exports.
Use it like you would use Ky:
1import ky from 'ky-universal'; 2 3const parsed = await ky('https://httpbin.org/json').json(); 4 5// …
Webpack will ensure the polyfills are only included and used when the app is rendered on the server-side.
Put the following in package.json:
1{ 2 "ava": { 3 "require": [ 4 "ky-universal" 5 ] 6 } 7}
The library that uses Ky will now just work in AVA tests.
clone()
hangs with a large response in Node - What should I do?Streams in Node.js have a smaller internal buffer size (16 kB, aka highWaterMark
) than browsers (>1 MB, not consistent across browsers). When using Ky, the default highWaterMark
is set to 10 MB, so you shouldn't encounter many issues related to that.
However, you can specify a custom highWaterMark
if needed:
1import ky from 'ky-universal'; 2 3const response = await ky('https://example.com', { 4 // 20 MB 5 highWaterMark: 1000 * 1000 * 20 6}); 7 8const data = await response.clone().buffer();
No vulnerabilities found.
No security vulnerabilities found.