Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ky

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ky - npm Package Compare versions

Comparing version 0.33.3 to 1.0.0

2

distribution/core/constants.js

@@ -7,3 +7,3 @@ export const supportsRequestStreams = (() => {

if (supportsReadableStream && supportsRequest) {
hasContentType = new globalThis.Request('https://a.com', {
hasContentType = new globalThis.Request('https://empty.invalid', {
body: new globalThis.ReadableStream(),

@@ -10,0 +10,0 @@ method: 'POST',

import type { Input, InternalOptions, Options } from '../types/options.js';
import { ResponsePromise } from '../types/ResponsePromise.js';
import { type ResponsePromise } from '../types/ResponsePromise.js';
export declare class Ky {

@@ -4,0 +4,0 @@ static create(input: Input, options: Options): ResponsePromise;

@@ -9,7 +9,6 @@ import { HTTPError } from '../errors/HTTPError.js';

export class Ky {
// eslint-disable-next-line @typescript-eslint/promise-function-async
static create(input, options) {
const ky = new Ky(input, options);
const fn = async () => {
if (ky._options.timeout > maxSafeTimeout) {
if (typeof ky._options.timeout === 'number' && ky._options.timeout > maxSafeTimeout) {
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);

@@ -124,3 +123,3 @@ }

throwHttpErrors: options.throwHttpErrors !== false,
timeout: typeof options.timeout === 'undefined' ? 10000 : options.timeout,
timeout: options.timeout ?? 10000,
fetch: options.fetch ?? globalThis.fetch.bind(globalThis),

@@ -193,3 +192,3 @@ };

}
if (typeof this._options.retry.maxRetryAfter !== 'undefined' && after > this._options.retry.maxRetryAfter) {
if (this._options.retry.maxRetryAfter !== undefined && after > this._options.retry.maxRetryAfter) {
return 0;

@@ -217,3 +216,2 @@ }

return await fn();
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
}

@@ -220,0 +218,0 @@ catch (error) {

@@ -1,3 +0,3 @@

import { stop } from '../core/constants.js';
import { HTTPError } from '../index.js';
import { type stop } from '../core/constants.js';
import { type HTTPError } from '../index.js';
import type { NormalizedOptions } from './options.js';

@@ -14,3 +14,3 @@ export type BeforeRequestHook = (request: Request, options: NormalizedOptions) => Request | Response | void | Promise<Request | Response | void>;

export type BeforeErrorHook = (error: HTTPError) => HTTPError | Promise<HTTPError>;
export interface Hooks {
export type Hooks = {
/**

@@ -115,2 +115,2 @@ This hook enables you to modify the request right before it is sent. Ky will make no further changes to the request after this. The hook function receives normalized input and options as arguments. You could, forf example, modiy `options.headers` here.

beforeError?: BeforeErrorHook[];
}
};

@@ -1,5 +0,5 @@

import { stop } from '../core/constants.js';
import { type stop } from '../core/constants.js';
import type { Input, Options } from './options.js';
import type { ResponsePromise } from './ResponsePromise.js';
export interface KyInstance {
export type KyInstance = {
/**

@@ -110,2 +110,2 @@ Fetch the given `url`.

readonly stop: typeof stop;
}
};

@@ -8,3 +8,3 @@ import type { LiteralUnion, Required } from './common.js';

export type Input = string | URL | Request;
export interface DownloadProgress {
export type DownloadProgress = {
percent: number;

@@ -16,3 +16,3 @@ transferredBytes: number;

totalBytes: number;
}
};
export type KyHeadersInit = HeadersInit | Record<string, string | undefined>;

@@ -22,3 +22,3 @@ /**

*/
export interface Options extends Omit<RequestInit, 'headers'> {
export type Options = {
/**

@@ -206,3 +206,3 @@ HTTP method used to make the request.

fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
}
} & Omit<RequestInit, 'headers'>;
export type InternalOptions = Required<Omit<Options, 'hooks' | 'retry'>, 'credentials' | 'fetch' | 'prefixUrl' | 'timeout'> & {

@@ -217,3 +217,3 @@ headers: Required<Headers>;

*/
export interface NormalizedOptions extends RequestInit {
export type NormalizedOptions = {
method: RequestInit['method'];

@@ -224,3 +224,3 @@ credentials: RequestInit['credentials'];

onDownloadProgress: Options['onDownloadProgress'];
}
} & RequestInit;
export type { RetryOptions } from './retry.js';

@@ -1,3 +0,3 @@

export interface KyResponse extends Response {
export type KyResponse = {
json: <T = unknown>() => Promise<T>;
}
} & Response;
/**
Returns a `Response` object with `Body` methods added for convenience. So you can, for example, call `ky.get(input).json()` directly without having to await the `Response` first. When called like that, an appropriate `Accept` header will be set depending on the body method used. Unlike the `Body` methods of `window.Fetch`; these will throw an `HTTPError` if the response status is not in the range of `200...299`. Also, `.json()` will return an empty string if body is empty or the response status is `204` instead of throwing a parse error due to an empty body.
*/
import { KyResponse } from './response.js';
export interface ResponsePromise extends Promise<KyResponse> {
import { type KyResponse } from './response.js';
export type ResponsePromise = {
arrayBuffer: () => Promise<ArrayBuffer>;

@@ -32,2 +32,2 @@ blob: () => Promise<Blob>;

text: () => Promise<string>;
}
} & Promise<KyResponse>;

@@ -1,2 +0,2 @@

export interface RetryOptions {
export type RetryOptions = {
/**

@@ -47,2 +47,2 @@ The number of times to retry failed requests.

backoffLimit?: number;
}
};

@@ -1,5 +0,5 @@

import { InternalOptions } from '../types/options.js';
export interface DelayOptions {
import { type InternalOptions } from '../types/options.js';
export type DelayOptions = {
signal?: InternalOptions['signal'];
}
};
export default function delay(ms: number, { signal }: DelayOptions): Promise<void>;
// https://github.com/sindresorhus/delay/tree/ab98ae8dfcb38e1593286c94d934e70d14a4e111
import { composeAbortError } from '../errors/DOMException.js';
export default async function delay(ms, { signal }) {
return new Promise((resolve, reject) => {
if (signal) {
if (signal.aborted) {
reject(composeAbortError(signal));
return;
}
signal.addEventListener('abort', handleAbort, { once: true });
signal.throwIfAborted();
signal.addEventListener('abort', abortHandler, { once: true });
}
function handleAbort() {
reject(composeAbortError(signal));
function abortHandler() {
clearTimeout(timeoutId);
reject(signal.reason);
}
const timeoutId = setTimeout(() => {
signal?.removeEventListener('abort', handleAbort);
signal?.removeEventListener('abort', abortHandler);
resolve();

@@ -19,0 +15,0 @@ }, ms);

import { isObject } from './is.js';
export const validateAndMerge = (...sources) => {
for (const source of sources) {
if ((!isObject(source) || Array.isArray(source)) && typeof source !== 'undefined') {
if ((!isObject(source) || Array.isArray(source)) && source !== undefined) {
throw new TypeError('The `options` argument must be an object');

@@ -6,0 +6,0 @@ }

{
"name": "ky",
"version": "0.33.3",
"version": "1.0.0",
"description": "Tiny and elegant HTTP client based on the browser Fetch API",

@@ -14,7 +14,10 @@ "license": "MIT",

"type": "module",
"exports": {
"types": "./distribution/index.d.ts",
"default": "./distribution/index.js"
},
"main": "./distribution/index.js",
"exports": "./distribution/index.js",
"types": "./distribution/index.d.ts",
"engines": {
"node": ">=14.16"
"node": ">=18"
},

@@ -54,25 +57,21 @@ "scripts": {

"devDependencies": {
"@sindresorhus/tsconfig": "^3.0.1",
"@sindresorhus/tsconfig": "^4.0.0",
"@type-challenges/utils": "^0.1.1",
"@types/body-parser": "^1.19.2",
"@types/busboy": "^0.3.1",
"@types/express": "^4.17.14",
"@types/node": "^18.11.7",
"@types/node-fetch": "^2.6.2",
"abort-controller": "^3.0.0",
"ava": "^4.3.3",
"body-parser": "^1.20.1",
"busboy": "^0.3.1",
"del-cli": "^4.0.1",
"delay": "^5.0.0",
"expect-type": "^0.14.2",
"@types/busboy": "^1.5.0",
"@types/express": "^4.17.17",
"@types/node": "^20.5.7",
"ava": "^5.3.1",
"body-parser": "^1.20.2",
"busboy": "^1.6.0",
"del-cli": "^5.1.0",
"delay": "^6.0.0",
"expect-type": "^0.16.0",
"express": "^4.18.2",
"form-data": "^4.0.0",
"node-fetch": "^2.6.1",
"pify": "^6.1.0",
"playwright-chromium": "^1.27.1",
"raw-body": "^2.5.1",
"ts-node": "^10.8.1",
"typescript": "^4.8.4",
"xo": "^0.50.0"
"playwright-chromium": "^1.37.1",
"raw-body": "^2.5.2",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"xo": "^0.56.0"
},

@@ -84,5 +83,2 @@ "sideEffects": false,

],
"globals": [
"globalThis"
],
"rules": {

@@ -99,5 +95,2 @@ "unicorn/filename-case": "off",

"ava": {
"require": [
"./test/_require.ts"
],
"extensions": {

@@ -104,0 +97,0 @@ "ts": "module"

@@ -43,3 +43,3 @@ <div align="center">

Ky targets [modern browsers](#browser-support) and [Deno](https://github.com/denoland/deno). For older browsers, you will need to transpile and use a [`fetch` polyfill](https://github.com/github/fetch) and [`globalThis` polyfill](https://github.com/es-shims/globalThis). For isomorphic needs (Node.js + browser, like SSR), check out [`ky-universal`](https://github.com/sindresorhus/ky-universal).
Ky targets [modern browsers](#browser-support), Node.js, and Deno.

@@ -622,7 +622,7 @@ It's just a tiny file with no dependencies.

Check out [`ky-universal`](https://github.com/sindresorhus/ky-universal#faq).
Node.js 18 and later supports `fetch` natively, so you can just use this package directly.
#### How do I use this with a web app (React, Vue.js, etc.) that uses server-side rendering (SSR)?
Check out [`ky-universal`](https://github.com/sindresorhus/ky-universal#faq).
Same as above.

@@ -672,7 +672,6 @@ #### How do I test a browser library that uses this?

Polyfill the needed browser globals or just use [`ky-universal`](https://github.com/sindresorhus/ky-universal).
Node.js 18 and later.
## Related
- [ky-universal](https://github.com/sindresorhus/ky-universal) - Use Ky in both Node.js and browsers
- [got](https://github.com/sindresorhus/got) - Simplified HTTP requests for Node.js

@@ -679,0 +678,0 @@ - [ky-hooks-change-case](https://github.com/alice-health/ky-hooks-change-case) - Ky hooks to modify cases on requests and responses of objects

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc