Skip to content
Myr

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

6 files+40 added−38 removed

modified:test/main.js+8 added-8 removed
331 unmodified lines
332 server.get('/', (request, response) => {333 response.end(request.url.slice(1));334 });335336 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';344345 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);349350 await server.close();351});352
235 unmodified lines
modified:index.d.ts+20 added-20 removed
12 unmodified lines
13 options: NormalizedOptions,14) => Request | Response | void | Promise<Request | Response | void>;1516export 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>;2324export type AfterResponseHook = (25 request: Request,
302 unmodified lines
328/**329Returns 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*/331export interface ResponsePromise extends Promise<Response> {332 arrayBuffer(): Promise<ArrayBuffer>;332 arrayBuffer: () => Promise<ArrayBuffer>;333334 blob(): Promise<Blob>;334 blob: () => Promise<Blob>;335336 formData(): Promise<FormData>;336 formData: () => Promise<FormData>;337338 // 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 lines
357358 const result = await ky(…).json<Result>();359 ```360 */361 json<T>(): Promise<T>;361 json: <T>() => Promise<T>;362363 text(): Promise<string>;363 text: () => Promise<string>;364}365366/**367The error has a response property with the `Response` object.
36 unmodified lines
404405 @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;409410 /**411 Fetch the given `url` using the option `{method: 'post'}`.412413 @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;417418 /**419 Fetch the given `url` using the option `{method: 'put'}`.420421 @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;425426 /**427 Fetch the given `url` using the option `{method: 'delete'}`.428429 @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;433434 /**435 Fetch the given `url` using the option `{method: 'patch'}`.436437 @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;441442 /**443 Fetch the given `url` using the option `{method: 'head'}`.444445 @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;449450 /**451 Create a new Ky instance with complete new defaults.452453 @returns A new Ky instance.454 */455 create(defaultOptions: Options): typeof ky;455 create: (defaultOptions: Options) => typeof ky;456457 /**458 Create a new Ky instance with some defaults overridden with your own.459460 In contrast to `ky.create()`, `ky.extend()` inherits defaults from its parent.461462 @returns A new Ky instance.463 */464 extend(defaultOptions: Options): typeof ky;464 extend: (defaultOptions: Options) => typeof ky;465466 /**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 lines
492 readonly HTTPError: typeof HTTPError;493};494495declare 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}499500export default ky;
modified:index.test-d.ts+7 added-5 removed
modified:license+1 added-1 removed
1MIT License23Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)3Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)45Permission 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:67The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2 unmodified lines
modified:package.json+3 added-3 removed
6 unmodified lines
7 "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 lines
57 "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 lines
modified:readme.md+1 added-1 removed
125 unmodified lines
126127##### method128129Type: `string`\130Default: `get`130Default: `'get'`131132HTTP method used to make the request.133134Internally, 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