From 0b93fa8cbe334aaf7625993e7a566b2452144696 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 15 Nov 2019 13:59:11 +0700 Subject: [PATCH] Meta tweaks --- index.d.ts | 2 +- index.js | 2 +- index.test-d.ts | 9 ++++----- package.json | 6 +++--- readme.md | 18 +++++++++--------- test/browser.js | 8 ++++---- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/index.d.ts b/index.d.ts index 57f98f5a..92b351d0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -276,7 +276,7 @@ export interface Options extends RequestInit { /** Normalized options passed to the `fetch` call and the `beforeRequest` hooks. */ -interface NormalizedOptions extends RequestInit { +export interface NormalizedOptions extends RequestInit { // Extended from `RequestInit`, but ensured to be set (not optional). method: RequestInit['method']; credentials: RequestInit['credentials']; diff --git a/index.js b/index.js index 53e93af6..3068db16 100644 --- a/index.js +++ b/index.js @@ -360,7 +360,7 @@ class Ky { this.request, this._options, error, - this._retryCount, + this._retryCount ); // If `stop` is returned from the hook, the retry process is stopped diff --git a/index.test-d.ts b/index.test-d.ts index 4237154f..bf07f7d9 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import ky, {HTTPError, TimeoutError, ResponsePromise, DownloadProgress, Options, Input} from '.'; +import ky, {HTTPError, TimeoutError, ResponsePromise, DownloadProgress, Options, NormalizedOptions, Input} from '.'; const url = 'https://sindresorhus'; @@ -25,14 +25,13 @@ expectType(ky.create({})); expectType(ky.extend({})); expectType(new HTTPError(new Response)); expectType(new TimeoutError); -expectType(ky.stop); ky(url, { hooks: { beforeRequest: [ (request, options) => { expectType(request); - expectType(options); + expectType(options); request.headers.set('foo', 'bar'); }, (_request, _options) => { @@ -51,7 +50,7 @@ ky(url, { beforeRetry: [ (request, options, error, retryCount) => { expectType(request); - expectType(options); + expectType(options); expectType(error); expectType(retryCount); request.headers.set('foo', 'bar'); @@ -60,7 +59,7 @@ ky(url, { afterResponse: [ (request, options, response) => { expectType(request); - expectType(options); + expectType(options); expectType(response); }, (_request, _options, _response) => { diff --git a/package.json b/package.json index 41b07ca6..42771a28 100644 --- a/package.json +++ b/package.json @@ -56,9 +56,9 @@ "node-fetch": "^2.5.0", "nyc": "^14.1.1", "puppeteer": "^1.15.0", - "rollup": "^1.11.3", - "tsd": "^0.7.2", - "xo": "^0.24.0" + "rollup": "^1.27.0", + "tsd": "^0.11.0", + "xo": "^0.25.3" }, "xo": { "envs": [ diff --git a/readme.md b/readme.md index 316ea72e..481a9eea 100644 --- a/readme.md +++ b/readme.md @@ -130,7 +130,7 @@ Type: `object` ##### method -Type: `string`
+Type: `string`\ Default: `get` HTTP method used to make the request. @@ -145,7 +145,7 @@ Shortcut for sending JSON. Use this instead of the `body` option. Accepts a plai ##### searchParams -Type: `string | object | Array> | URLSearchParams`
+Type: `string | object | Array> | URLSearchParams`\ Default: `''` Search parameters to include in the request URL. Setting this will override all existing search parameters in the input URL. @@ -180,7 +180,7 @@ Notes: ##### retry -Type: `object | number`
+Type: `object | number`\ Default: - `limit`: `2` @@ -212,7 +212,7 @@ import ky from 'ky'; ##### timeout -Type: `number | false`
+Type: `number | false`\ Default: `10000` Timeout in milliseconds for getting a response. Can not be greater than 2147483647. @@ -220,14 +220,14 @@ If set to `false`, there will be no timeout. ##### hooks -Type: `object`
+Type: `object`\ Default: `{beforeRequest: [], beforeRetry: [], afterResponse: []}` Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially. ###### hooks.beforeRequest -Type: `Function[]`
+Type: `Function[]`\ Default: `[]` 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 `request` and `options` as arguments. You could, for example, modify the `request.headers` here. @@ -255,7 +255,7 @@ const api = ky.extend({ ###### hooks.beforeRetry -Type: `Function[]`
+Type: `Function[]`\ Default: `[]` This hook enables you to modify the request right before retry. Ky will make no further changes to the request after this. The hook function receives the normalized request and options, an error instance and the retry count as arguments. You could, for example, modify `request.headers` here. @@ -279,7 +279,7 @@ import ky from 'ky'; ###### hooks.afterResponse -Type: `Function[]`
+Type: `Function[]`\ Default: `[]` This hook enables you to read and optionally modify the response. The hook function receives normalized request, options, and a clone of the response as arguments. The return value of the hook function will be used by Ky as the response object if it's an instance of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response). @@ -319,7 +319,7 @@ import ky from 'ky'; ##### throwHttpErrors -Type: `boolean`
+Type: `boolean`\ Default: `true` Throw a `HTTPError` for error responses (non-2xx status codes). diff --git a/test/browser.js b/test/browser.js index 9c8cca12..9cabfdb2 100644 --- a/test/browser.js +++ b/test/browser.js @@ -57,7 +57,7 @@ test('aborting a request', withPage, async (t, page) => { const controller = new AbortController(); const request = window.ky(`${url}/test`, {signal: controller.signal}).text(); controller.abort(); - return request.catch(error => error.toString()); + return request.catch(error_ => error_.toString()); }, server.url); t.is(error, 'AbortError: The user aborted a request.'); @@ -82,7 +82,7 @@ test('throws TimeoutError even though it does not support AbortController', with window.ky = window.ky.default; const request = window.ky(`${url}/endless`, {timeout: 500}).text(); - return request.catch(error => error.toString()); + return request.catch(error_ => error_.toString()); }, server.url); t.is(error, 'TimeoutError: Request timed out'); @@ -148,7 +148,7 @@ test('throws if onDownloadProgress is not a function', withPage, async (t, page) window.ky = window.ky.default; const request = window.ky(url, {onDownloadProgress: 1}).text(); - return request.catch(error => error.toString()); + return request.catch(error_ => error_.toString()); }, server.url); t.is(error, 'TypeError: The `onDownloadProgress` option must be a function'); @@ -170,7 +170,7 @@ test('throws if does not support ReadableStream', withPage, async (t, page) => { window.ky = window.ky.default; const request = window.ky(url, {onDownloadProgress: () => {}}).text(); - return request.catch(error => error.toString()); + return request.catch(error_ => error_.toString()); }, server.url); t.is(error, 'Error: Streams are not supported in your environment. `ReadableStream` is missing.');