Meta tweaks
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sindre Sorhus · committed by Sindre Sorhus · parent 70826b2 · Browse files · 6 files·+40 added−38 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+40 added−38 removed
- tests:+8 added−8 removed
- other:+32 added−30 removed
Provenance
- Commit
588f453- Tree
e4aebeb- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
70826b2
6 files changed+40 added−38 removed
modified:test/main.js+8 added-8 removed
331 unmodified lines332 server.get('/', (request, response) => {333 response.end(request.url.slice(1));334 });335 336- const arrayParams = [['cats', 'meow'], ['dogs', true], ['opossums', false]];337- const objectParams = {336+ const arrayParameters = [['cats', 'meow'], ['dogs', true], ['opossums', false]];337+ const objectParameters = {338 cats: 'meow',339 dogs: true,340 opossums: false341 };342- const searchParams = new URLSearchParams(arrayParams);343- const stringParams = '?cats=meow&dogs=true&opossums=false';342+ const searchParameters = new URLSearchParams(arrayParameters);343+ const stringParameters = '?cats=meow&dogs=true&opossums=false';344 345- t.is(await ky(server.url, {searchParams: arrayParams}).text(), stringParams);346- t.is(await ky(server.url, {searchParams: objectParams}).text(), stringParams);347- t.is(await ky(server.url, {searchParams}).text(), stringParams);348- t.is(await ky(server.url, {searchParams: stringParams}).text(), stringParams);345+ t.is(await ky(server.url, {searchParams: arrayParameters}).text(), stringParameters);346+ t.is(await ky(server.url, {searchParams: objectParameters}).text(), stringParameters);347+ t.is(await ky(server.url, {searchParams: searchParameters}).text(), stringParameters);348+ t.is(await ky(server.url, {searchParams: stringParameters}).text(), stringParameters);349 350 await server.close();351 });352 235 unmodified linesmodified:index.d.ts+20 added-20 removed
12 unmodified lines13 options: NormalizedOptions,14 ) => Request | Response | void | Promise<Request | Response | void>;15 16 export type BeforeRetryHook = (options: {17- request: Request,18- response: Response,19- options: NormalizedOptions,20- error: Error,21- retryCount: number,17+ request: Request;18+ response: Response;19+ options: NormalizedOptions;20+ error: Error;21+ retryCount: number;22 }) => void | Promise<void>;23 24 export type AfterResponseHook = (25 request: Request,302 unmodified lines328 /**329 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 the response status is `204` instead of throwing a parse error due to an empty body.330 */331 export interface ResponsePromise extends Promise<Response> {332- arrayBuffer(): Promise<ArrayBuffer>;332+ arrayBuffer: () => Promise<ArrayBuffer>;333 334- blob(): Promise<Blob>;334+ blob: () => Promise<Blob>;335 336- formData(): Promise<FormData>;336+ formData: () => Promise<FormData>;337 338 // TODO: Use `json<T extends JSONValue>(): Promise<T>;` when it's fixed in TS.339 // See https://github.com/microsoft/TypeScript/issues/15300 and https://github.com/sindresorhus/ky/pull/80340 /**16 unmodified lines357 358 const result = await ky(…).json<Result>();359 ```360 */361- json<T>(): Promise<T>;361+ json: <T>() => Promise<T>;362 363- text(): Promise<string>;363+ text: () => Promise<string>;364 }365 366 /**367 The error has a response property with the `Response` object.36 unmodified lines404 405 @param url - `Request` object, `URL` object, or URL string.406 @returns A promise with `Body` methods added.407 */408- get(url: Input, options?: Options): ResponsePromise;408+ get: (url: Input, options?: Options) => ResponsePromise;409 410 /**411 Fetch the given `url` using the option `{method: 'post'}`.412 413 @param url - `Request` object, `URL` object, or URL string.414 @returns A promise with `Body` methods added.415 */416- post(url: Input, options?: Options): ResponsePromise;416+ post: (url: Input, options?: Options) => ResponsePromise;417 418 /**419 Fetch the given `url` using the option `{method: 'put'}`.420 421 @param url - `Request` object, `URL` object, or URL string.422 @returns A promise with `Body` methods added.423 */424- put(url: Input, options?: Options): ResponsePromise;424+ put: (url: Input, options?: Options) => ResponsePromise;425 426 /**427 Fetch the given `url` using the option `{method: 'delete'}`.428 429 @param url - `Request` object, `URL` object, or URL string.430 @returns A promise with `Body` methods added.431 */432- delete(url: Input, options?: Options): ResponsePromise;432+ delete: (url: Input, options?: Options) => ResponsePromise;433 434 /**435 Fetch the given `url` using the option `{method: 'patch'}`.436 437 @param url - `Request` object, `URL` object, or URL string.438 @returns A promise with `Body` methods added.439 */440- patch(url: Input, options?: Options): ResponsePromise;440+ patch: (url: Input, options?: Options) => ResponsePromise;441 442 /**443 Fetch the given `url` using the option `{method: 'head'}`.444 445 @param url - `Request` object, `URL` object, or URL string.446 @returns A promise with `Body` methods added.447 */448- head(url: Input, options?: Options): ResponsePromise;448+ head: (url: Input, options?: Options) => ResponsePromise;449 450 /**451 Create a new Ky instance with complete new defaults.452 453 @returns A new Ky instance.454 */455- create(defaultOptions: Options): typeof ky;455+ create: (defaultOptions: Options) => typeof ky;456 457 /**458 Create a new Ky instance with some defaults overridden with your own.459 460 In contrast to `ky.create()`, `ky.extend()` inherits defaults from its parent.461 462 @returns A new Ky instance.463 */464- extend(defaultOptions: Options): typeof ky;464+ extend: (defaultOptions: Options) => typeof ky;465 466 /**467 A `Symbol` that can be returned by a `beforeRetry` hook to stop the retry.468 This will also short circuit the remaining `beforeRetry` hooks.23 unmodified lines492 readonly HTTPError: typeof HTTPError;493 };494 495 declare namespace ky {496- export type TimeoutError = InstanceType<typeof ky.TimeoutError>;497- export type HTTPError = InstanceType<typeof ky.HTTPError>;496+ export type TimeoutError = InstanceType<typeof TimeoutError>;497+ export type HTTPError = InstanceType<typeof HTTPError>;498 }499 500 export default ky;modified:index.test-d.ts+7 added-5 removed
10 unmodified lines1112131415151617181959 unmodified lines79808182838483848586878889909192929394959697989910010110249 unmodified lines15215315415515415615715810 unmodified lines 'post', 'put', 'delete', 'patch', 'head', 'head'] as const;
// Test Ky HTTP methodsfor (const method of requestMethods) {59 unmodified lines// Reusable typesconst input: Input = new URL('https://sindresorhus');const options: Options = { method: 'get', timeout: 5000,} timeout: 5000};ky(input, options);
// Extending Kyinterface CustomOptions extends Options { foo?: boolean;}async function customKy(input: Input, options?: CustomOptions) { if (options && options.foo) { if (options?.foo) { options.json = {foo: options.foo}; }
return ky(input, options);}
customKy(input, options);
// `searchParams` optionky(url, {searchParams: 'foo=bar'});49 unmodified lines expectType<number>(status); } else if (error instanceof ky.TimeoutError) { expectType<ky.TimeoutError>(error); } else { throw error; throw error; }}modified:license+1 added-1 removed
1 MIT License2 3-Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)3+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)4 5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:6 7 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.2 unmodified linesmodified:package.json+3 added-3 removed
6 unmodified lines7 "funding": "https://github.com/sindresorhus/ky?sponsor=1",8 "author": {9 "name": "Sindre Sorhus",10 "email": "sindresorhus@gmail.com",11- "url": "sindresorhus.com"11+ "url": "https://sindresorhus.com"12 },13 "engines": {14 "node": ">=10"15 },41 unmodified lines57 "esm": "^3.2.22",58 "form-data": "^3.0.0",59 "node-fetch": "^2.5.0",60 "nyc": "^15.0.0",61- "puppeteer": "^2.1.0",62- "rollup": "^1.31.0",61+ "puppeteer": "^3.0.4",62+ "rollup": "^2.10.2",63 "tsd": "^0.11.0",64 "xo": "^0.25.3"65 },66 "sideEffects": false,15 unmodified linesmodified:readme.md+1 added-1 removed
125 unmodified lines126 127 ##### method128 129 Type: `string`\130-Default: `get`130+Default: `'get'`131 132 HTTP method used to make the request.133 134 Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.455 unmodified lines