UNPKG

ky

Version:

Tiny and elegant HTTP client based on the Fetch API

16 lines • 1.59 kB
// eslint-disable-next-line @typescript-eslint/no-restricted-types export const isObject = (value) => value !== null && typeof value === 'object'; // eslint-disable-next-line @typescript-eslint/no-restricted-types export const isNonArrayObject = (value) => isObject(value) && !Array.isArray(value); // `NaN` fails the comparison, so it is rejected too. export const isNonNegativeNumber = (value) => typeof value === 'number' && value >= 0; const objectToString = Object.prototype.toString; // An `Error` from another realm (an iframe, a worker, a `vm` context, or a duplicated dependency) fails `instanceof`, so the internal brand is checked as well, the same way the request and response checks do. `instanceof` stays first because it also accepts `DOMException`, which an `AbortSignal` reason is, and that does not carry the `[object Error]` brand. export const isError = (value) => value instanceof Error || objectToString.call(value) === '[object Error]'; // A `Request` from another realm, such as one a hook built in an iframe, is accepted through its internal brand. export const isRequest = (value) => value instanceof globalThis.Request || objectToString.call(value) === '[object Request]'; // Accepted custom responses are treated as full Responses throughout Ky. // If a custom fetch returns one, it must behave like a Response for cloning, // body consumption, `json()` decoration, and any enabled stream features. export const isResponse = (value) => value instanceof globalThis.Response || objectToString.call(value) === '[object Response]'; //# sourceMappingURL=is.js.map