Socket
Socket
Sign inDemoInstall

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 1.1.0 to 1.1.1

distribution/utils/options.d.ts

2

distribution/core/constants.d.ts

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

import { type KyOptionsRegistry } from '../types/options.js';
export declare const supportsRequestStreams: boolean;

@@ -15,1 +16,2 @@ export declare const supportsAbortController: boolean;

export declare const stop: unique symbol;
export declare const kyOptionKeys: KyOptionsRegistry;

@@ -35,2 +35,14 @@ export const supportsRequestStreams = (() => {

export const stop = Symbol('stop');
export const kyOptionKeys = {
json: true,
parseJson: true,
searchParams: true,
prefixUrl: true,
retry: true,
timeout: true,
hooks: true,
throwHttpErrors: true,
onDownloadProgress: true,
fetch: true,
};
//# sourceMappingURL=constants.js.map

6

distribution/core/Ky.js

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

import delay from '../utils/delay.js';
import { findUnknownOptions } from '../utils/options.js';
import { maxSafeTimeout, responseTypes, stop, supportsAbortController, supportsFormData, supportsResponseStreams, supportsRequestStreams, } from './constants.js';

@@ -249,6 +250,7 @@ export class Ky {

}
const nonRequestOptions = findUnknownOptions(this.request, this._options);
if (this._options.timeout === false) {
return this._options.fetch(this.request.clone());
return this._options.fetch(this.request.clone(), nonRequestOptions);
}
return timeout(this.request.clone(), this.abortController, this._options);
return timeout(this.request.clone(), nonRequestOptions, this.abortController, this._options);
}

@@ -255,0 +257,0 @@ /* istanbul ignore next */

@@ -18,48 +18,6 @@ import type { LiteralUnion, Required } from './common.js';

/**
Options are the same as `window.fetch`, with some exceptions.
Custom Ky options
*/
export interface Options extends Omit<RequestInit, 'headers'> {
export type KyOptions = {
/**
HTTP method used to make the request.
Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.
*/
method?: LiteralUnion<HttpMethod, string>;
/**
HTTP headers used to make the request.
You can pass a `Headers` instance or a plain object.
You can remove a header with `.extend()` by passing the header with an `undefined` value.
@example
```
import ky from 'ky';
const url = 'https://sindresorhus.com';
const original = ky.create({
headers: {
rainbow: 'rainbow',
unicorn: 'unicorn'
}
});
const extended = original.extend({
headers: {
rainbow: undefined
}
});
const response = await extended(url).json();
console.log('rainbow' in response);
//=> false
console.log('unicorn' in response);
//=> true
```
*/
headers?: KyHeadersInit;
/**
Shortcut for sending JSON. Use this instead of the `body` option.

@@ -204,2 +162,57 @@

fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
};
/**
Each key from KyOptions is present and set to `true`.
This type is used for identifying and working with the known keys in KyOptions.
*/
export type KyOptionsRegistry = {
[K in keyof KyOptions]-?: true;
};
/**
Options are the same as `window.fetch`, except for the KyOptions
*/
export interface Options extends KyOptions, Omit<RequestInit, 'headers'> {
/**
HTTP method used to make the request.
Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.
*/
method?: LiteralUnion<HttpMethod, string>;
/**
HTTP headers used to make the request.
You can pass a `Headers` instance or a plain object.
You can remove a header with `.extend()` by passing the header with an `undefined` value.
@example
```
import ky from 'ky';
const url = 'https://sindresorhus.com';
const original = ky.create({
headers: {
rainbow: 'rainbow',
unicorn: 'unicorn'
}
});
const extended = original.extend({
headers: {
rainbow: undefined
}
});
const response = await extended(url).json();
console.log('rainbow' in response);
//=> false
console.log('unicorn' in response);
//=> true
```
*/
headers?: KyHeadersInit;
}

@@ -206,0 +219,0 @@ export type InternalOptions = Required<Omit<Options, 'hooks' | 'retry'>, 'credentials' | 'fetch' | 'prefixUrl' | 'timeout'> & {

@@ -5,2 +5,2 @@ export type TimeoutOptions = {

};
export default function timeout(request: Request, abortController: AbortController | undefined, options: TimeoutOptions): Promise<Response>;
export default function timeout(request: Request, init: RequestInit, abortController: AbortController | undefined, options: TimeoutOptions): Promise<Response>;
import { TimeoutError } from '../errors/TimeoutError.js';
// `Promise.race()` workaround (#91)
export default async function timeout(request, abortController, options) {
export default async function timeout(request, init, abortController, options) {
return new Promise((resolve, reject) => {

@@ -12,3 +12,3 @@ const timeoutId = setTimeout(() => {

void options
.fetch(request)
.fetch(request, init)
.then(resolve)

@@ -15,0 +15,0 @@ .catch(reject)

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

@@ -5,0 +5,0 @@ "license": "MIT",

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