Fix minor typos and improve backtick consistency (#853)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Rohit Nair P · committed by GitHub · parent d375014 · Browse files · 4 files·+15 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+15 added−15 removed
- other:+15 added−15 removed
Provenance
- Commit
a376fc4- Tree
de12c7e- Author
Rohit Nair P <rohitnairmuttathethu@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
d375014
4 files changed+15 added−15 removed
modified:source/core/Ky.ts+1 added-1 removed
216 unmodified lines217 218 let processedError: Error = error;219 for (const hook of ky.#options.hooks.beforeError) {220 // `request` is the current failing request. `options` intentionally remains the221- // stable normalized Ky options snapshot for the same reason as HTTPError above.221+ // stable normalized Ky options snapshot for the same reason as `HTTPError` above.222 // eslint-disable-next-line no-await-in-loop223 const hookResult: unknown = await hook({224 request: ky.request,225 options: ky.#getNormalizedOptions(),756 unmodified linesmodified:source/types/options.ts+2 added-2 removed
111 unmodified lines112 113 /**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`.115 116- Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.116+ Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky instances.117 118 If the `baseUrl` itself is relative, it will be resolved against the environment's base URL, such as [`document.baseURI`](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) in browsers or `location.href` in Deno (see the `--location` flag).119 120 **Tip:** When setting a `baseUrl` that has a path, we recommend that it include a trailing slash `/`, as in `'/api/'` rather than `/api`. This ensures more intuitive behavior for page-relative `input` URLs, such as `'users'` or `'./users'`, where they will _extend_ from the full path of the `baseUrl` rather than _replacing_ its last path segment.15 unmodified lines136 137 /**138 A prefix to prepend to the `input` before making the request (and before it is resolved against the `baseUrl`). It can be any valid path or URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string.139 140- Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.140+ Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky instances.141 142 *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.*143 144 Notes:321 unmodified linesmodified:source/utils/type-guards.ts+9 added-9 removed
7 unmodified lines89101112121314151619 unmodified lines363738394040414243434445464710 unmodified lines585960616262636465656667686910 unmodified lines808182838484858687878889909110 unmodified lines10210310410510610610710810910911011111211317 unmodified lines7 unmodified linesconst isErrorType = (error: unknown, cls: {name: string}): boolean => error instanceof (cls as any) || (error as any)?.name === cls.name;
/**Type guard to check if an error is a Ky error.Type guard to check if an error is a `KyError`.
Note: `SchemaValidationError` is intentionally not considered a Ky error. `KyError` covers failures in Ky's HTTP lifecycle (bad status, timeout, retry), while schema validation errors originate from the user-provided schema, not from Ky itself.
@param error - The error to check19 unmodified lines return (error as any)?.isKyError === true || isHTTPError(error) || isNetworkError(error) || isTimeoutError(error) || isForceRetryError(error);}
/**Type guard to check if an error is an HTTPError.Type guard to check if an error is an `HTTPError`.
@param error - The error to check@returns `true` if the error is an HTTPError, `false` otherwise@returns `true` if the error is an `HTTPError`, `false` otherwise
@example```import ky, {isHTTPError} from 'ky';10 unmodified lines return isErrorType(error, HTTPError);}
/**Type guard to check if an error is a NetworkError.Type guard to check if an error is a `NetworkError`.
@param error - The error to check@returns `true` if the error is a NetworkError, `false` otherwise@returns `true` if the error is a `NetworkError`, `false` otherwise
@example```import ky, {isNetworkError} from 'ky';10 unmodified lines return isErrorType(error, NetworkError);}
/**Type guard to check if an error is a TimeoutError.Type guard to check if an error is a `TimeoutError`.
@param error - The error to check@returns `true` if the error is a TimeoutError, `false` otherwise@returns `true` if the error is a `TimeoutError`, `false` otherwise
@example```import ky, {isTimeoutError} from 'ky';10 unmodified lines return isErrorType(error, TimeoutError);}
/**Type guard to check if an error is a ForceRetryError.Type guard to check if an error is a `ForceRetryError`.
@param error - The error to check@returns `true` if the error is a ForceRetryError, `false` otherwise@returns `true` if the error is a `ForceRetryError`, `false` otherwise
@example```import ky, {isForceRetryError} from 'ky';17 unmodified linesmodified:readme.md+3 added-3 removed
220 unmodified lines221 Type: `string | URL`222 223 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`.224 225-Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.225+Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky instances.226 227 If the `baseUrl` itself is relative, it will be resolved against the environment's base URL, such as [`document.baseURI`](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) in browsers or `location.href` in Deno (see the `--location` flag).228 229 **Tip:** When setting a `baseUrl` that has a path, we recommend that it include a trailing slash `/`, as in `'/api/'` rather than `/api`. This ensures more intuitive behavior for page-relative `input` URLs, such as `'users'` or `'./users'`, where they will _extend_ from the full path of the `baseUrl` rather than _replacing_ its last path segment.15 unmodified lines245 Type: `string | URL`246 247 A prefix to prepend to the `input` before making the request (and before it is resolved against the `baseUrl`). It can be any valid path or URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string.248 249-Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.249+Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky instances.250 251 *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.*252 253 ```js802 unmodified lines1056 ]1057 }1058 };1059 1060-// Note that response will be `undefined` in case `ky.stop` is returned.1060+// Note that `response` will be `undefined` in case `ky.stop` is returned.1061 const response = await ky.post('https://example.com', options);1062 1063 // Using `.text()` or other body methods is not supported.1064 const text = await ky('https://example.com', options).text();610 unmodified lines