Installations
npm install ky-universal
Developer Guide
Typescript
Yes
Module System
ESM, UMD
Min. Node Version
>=16
Node Version
16.20.0
NPM Version
9.2.0
Score
98.8
Supply Chain
96.8
Quality
75.9
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (86.17%)
TypeScript (13.83%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
84,975,355
Last Day
35,931
Last Week
165,465
Last Month
713,830
Last Year
10,875,730
GitHub Statistics
672 Stars
46 Commits
20 Forks
6 Watching
1 Branches
9 Contributors
Bundle Size
356.00 B
Minified
239.00 B
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
0.12.0
Package Id
ky-universal@0.12.0
Unpacked Size
6.22 kB
Size
2.88 kB
File Count
7
NPM Version
9.2.0
Node Version
16.20.0
Publised On
28 Jul 2023
Total Downloads
Cumulative downloads
Total Downloads
84,975,355
Last day
1.7%
35,931
Compared to previous day
Last week
-8.2%
165,465
Compared to previous week
Last month
2.1%
713,830
Compared to previous month
Last year
-50.1%
10,875,730
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
ky-universal
Use Ky in both Node.js and browsers
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:
- Isomorphic code
- Web apps (React, Vue.js, etc.) that use server-side rendering (SSR)
- Testing browser libraries using a Node.js test runner
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.
Install
1npm install ky ky-universal
Note that you also need to install ky
.
Usage
1import ky from 'ky-universal'; 2 3const parsed = await ky('https://httpbin.org/json').json(); 4 5// …
ReadableStream
support
For 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// …
API
The API is exactly the same as the Ky API, including the named exports.
FAQ
How do I use this with a web app (React, Vue.js, etc.) that uses server-side rendering (SSR)?
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.
How do I test a browser library that uses Ky in AVA?
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();
Related
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
0 existing vulnerabilities detected
Reason
Found 6/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/ky-universal/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/ky-universal/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:22
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to ky-universal
satisfactory-server-api-client
Universal Satisfactory Server API client for JavaScript
@sm-iclient/monorepo
sm-iclient is a small subset of SuperMap iClient which is written in typescript, ESM module by default, and uses ky-universal as the HTTP request. By using ky-universal, it can be run on **node** and **browser**
@nichoth/ky-universal
Use Ky in both Node.js and browsers