Skip to content

Commit bbc98fc

Browse files
committed
Fix typos
1 parent 6d12e2d commit bbc98fc

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ It's just a tiny package with no dependencies.
2828
- Base URL option
2929
- Instances with custom defaults
3030
- Hooks
31-
- TypeScript niceties (e.g. `.json()` supports generics and defaults to `unknown`, not `any`)
31+
- TypeScript niceties (e.g., `.json()` supports generics and defaults to `unknown`, not `any`)
3232

3333
## Install
3434

@@ -197,7 +197,7 @@ When passing an object, setting a value to `undefined` deletes the parameter, wh
197197

198198
Type: `string | URL`
199199

200-
A base URL to [resolve](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references) the `input` against. When the `input` (after applying the `prefix` option) is only a relative URL, such as `'users'`, `'/users'`, or `'//my-site.com'`, it will be resolved against the `baseUrl` to determine the destination of the request. Otherwise, the `input` is absolute, such as `'https://my-site.com'`, and it will bypass the `baseUrl`.
200+
A base URL to [resolve](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references) the `input` against. When the `input` (after applying the `prefix` option) is only a relative URL, such as `'users'`, `'/users'`, or `'//my-site.com'`, it will be resolved against the `baseUrl` to determine the destination of the request. Otherwise, the `input` is absolute, such as `'https://my-site.com'`, and it will bypass the `baseUrl`.
201201

202202
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
203203

@@ -576,7 +576,7 @@ const response = await ky('https://example.com/api', {
576576
Type: `Function[]`\
577577
Default: `[]`
578578

579-
This hook enables you to modify any error right before it is thrown. The hook function receives a state object with the current request, the normalized Ky options, error, and retry count, and should return an `Error` instance.
579+
This hook enables you to modify any error right before it is thrown. The hook function receives a state object with the current request, the normalized Ky options, the error, and retry count, and should return an `Error` instance.
580580

581581
This hook is called for all error types, including `HTTPError`, `NetworkError`, `TimeoutError`, and `ForceRetryError` (when retry limit is exceeded via `ky.retry()`). Use type guards like `isHTTPError()`, `isNetworkError()`, or `isTimeoutError()` to handle specific error types.
582582

@@ -1207,7 +1207,7 @@ It also has a `data` property with the pre-parsed response body. For JSON respon
12071207
Be aware that some types of errors, such as network errors, inherently mean that a response was not received. In that case, the error will be an instance of [`NetworkError`](#networkerror) instead of `HTTPError` and will not contain a `response` property.
12081208
12091209
> [!NOTE]
1210-
> The response body is automatically consumed when populating `error.data`, so you do not need to manually consume or cancel `error.response.body`.
1210+
> The response body is automatically consumed when populating `error.data`, so `error.response.json()` and other body methods will not work. Use `error.data` instead. The `error.response` object is still available for headers, status, etc.
12111211
12121212
```js
12131213
import ky, {isHTTPError} from 'ky';

source/core/Ky.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class Ky {
150150
continue;
151151
}
152152

153-
// Opaque responses (`response.type === 'opaque'`) from `no-cors` requests always have `status: 0` and `ok: false`, but this is not a failure the actual status is hidden by the browser.
153+
// Opaque responses (`response.type === 'opaque'`) from `no-cors` requests always have `status: 0` and `ok: false`, but this is not a failure - the actual status is hidden by the browser.
154154
if (!response.ok && response.type !== 'opaque' && (
155155
typeof ky.#options.throwHttpErrors === 'function'
156156
? ky.#options.throwHttpErrors(response.status)
@@ -205,7 +205,7 @@ export class Ky {
205205
try {
206206
return await function_();
207207
} catch (error: unknown) {
208-
// Non-Error throws (e.g. thrown strings) pass through unchanged
208+
// Non-Error throws (e.g., thrown strings) pass through unchanged
209209
if (!(error instanceof Error)) {
210210
throw error;
211211
}
@@ -875,7 +875,7 @@ export class Ky {
875875
const request = this.#wrapRequestWithUploadProgress(this.request, this.#options.body ?? undefined);
876876

877877
// Cloning is done here to prepare in advance for retries.
878-
// Skip cloning when retries are disabled cloning a streaming body calls ReadableStream#tee()
878+
// Skip cloning when retries are disabled - cloning a streaming body calls ReadableStream#tee()
879879
// which buffers the entire stream in memory, causing excessive memory usage for large uploads.
880880
this.#originalRequest = request;
881881
if (retryRequest) {

source/core/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const responseTypes = {
5757
// The maximum value of a 32bit int (see issue #117)
5858
export const maxSafeTimeout = 2_147_483_647;
5959

60-
// Size in bytes of a typical form boundary (e.g. '------WebKitFormBoundaryaxpyiPgbbPti10Rw'), used to help estimate upload size
60+
// Size in bytes of a typical form boundary (e.g., '------WebKitFormBoundaryaxpyiPgbbPti10Rw'), used to help estimate upload size
6161
export const usualFormBoundarySize = 40;
6262

6363
/**
@@ -104,7 +104,7 @@ export type ForceRetryOptions = {
104104
} catch (error) {
105105
return ky.retry({
106106
code: 'VALIDATION_FAILED',
107-
cause: error // Preserves original error in chain
107+
cause: error // Preserves original error in chain
108108
});
109109
}
110110
```

source/errors/HTTPError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {KyError} from './KyError.js';
66
/**
77
Error thrown when the response has a non-2xx status code and `throwHttpErrors` is enabled.
88
9-
The error has a `response` property with the `Response` object, a `request` property with the `Request` object, an `options` property with the normalized options, and a `data` property with the pre-parsed response body.
9+
The error has a `response` property with the `Response` object, a `request` property with the `Request` object, an `options` property with the normalized options, and a `data` property with the pre-parsed response body. The response body is automatically consumed when populating `data`, so `response.json()` and other body methods will not work. Use `data` instead.
1010
*/
1111
export class HTTPError<T = unknown> extends KyError {
1212
override name = 'HTTPError' as const;

source/types/ResponsePromise.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
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 `undefined` if body is empty or the response status is `204` instead of throwing a parse error due to an empty body.
2+
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 `undefined` if body is empty or the response status is `204` instead of throwing a parse error due to an empty body.
33
*/
44
import {type KyResponse} from './response.js';
55
import type {StandardSchemaV1, StandardSchemaV1InferOutput} from './standard-schema.js';

source/types/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export type KyOptions = {
111111
searchParams?: SearchParamsOption;
112112

113113
/**
114-
A base URL to [resolve](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references) the `input` against. When the `input` (after applying the `prefix` option) is only a relative URL, such as `'users'`, `'/users'`, or `'//my-site.com'`, it will be resolved against the `baseUrl` to determine the destination of the request. Otherwise, the `input` is absolute, such as `'https://my-site.com'`, and it will bypass the `baseUrl`.
114+
A base URL to [resolve](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references) the `input` against. When the `input` (after applying the `prefix` option) is only a relative URL, such as `'users'`, `'/users'`, or `'//my-site.com'`, it will be resolved against the `baseUrl` to determine the destination of the request. Otherwise, the `input` is absolute, such as `'https://my-site.com'`, and it will bypass the `baseUrl`.
115115
116116
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
117117
@@ -142,8 +142,8 @@ export type KyOptions = {
142142
*In most cases, you should use the `baseUrl` option instead, as it is more consistent with web standards. However, `prefix` is useful if you want origin-relative `input` URLs, such as `/users`, to be treated as if they were page-relative. In other words, the leading slash of the `input` will essentially be ignored, because the `prefix` will become part of the `input` before URL resolution happens.*
143143
144144
Notes:
145-
- The `prefix` and `input` are joined with a slash `/`, and slashes are normalized at the join boundary by trimming trailing slashes from `prefix` and leading slashes from `input`.
146-
- After `prefix` and `input` are joined, the result is resolved against the `baseUrl` option, if present.
145+
- The `prefix` and `input` are joined with a slash `/`, and slashes are normalized at the join boundary by trimming trailing slashes from `prefix` and leading slashes from `input`.
146+
- After `prefix` and `input` are joined, the result is resolved against the `baseUrl` option, if present.
147147
148148
@example
149149
```

source/utils/type-guards.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {NetworkError} from '../errors/NetworkError.js';
44
import {TimeoutError} from '../errors/TimeoutError.js';
55
import {ForceRetryError} from '../errors/ForceRetryError.js';
66

7-
// Handles cross-realm cases (e.g. iframes, different JS contexts) where `instanceof` fails.
7+
// Handles cross-realm cases (e.g., iframes, different JS contexts) where `instanceof` fails.
88
const isErrorType = (error: unknown, cls: {name: string}): boolean =>
99
error instanceof (cls as any) || (error as any)?.name === cls.name;
1010

0 commit comments

Comments
 (0)