UNPKG

ky

Version:

Tiny and elegant HTTP client based on the Fetch API

31 lines 1.54 kB
/*! MIT License © Sindre Sorhus */ import { Ky } from './core/Ky.js'; import { requestMethods, stop, retry } from './core/constants.js'; import { validateAndMerge } from './utils/merge.js'; const createInstance = (defaults) => { // eslint-disable-next-line @typescript-eslint/promise-function-async const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options)); for (const method of requestMethods) { // eslint-disable-next-line @typescript-eslint/promise-function-async ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method })); } ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults)); ky.extend = (newDefaults) => { if (typeof newDefaults === 'function') { newDefaults = newDefaults(defaults ?? {}); } return createInstance(validateAndMerge(defaults, newDefaults)); }; ky.stop = stop; ky.retry = retry; return ky; }; const ky = createInstance(); export default ky; export { HTTPError } from './errors/HTTPError.js'; export { TimeoutError } from './errors/TimeoutError.js'; export { ForceRetryError } from './errors/ForceRetryError.js'; export { isKyError, isHTTPError, isTimeoutError, isForceRetryError, } from './utils/type-guards.js'; // Intentionally not exporting this for now as it's just an implementation detail and we don't want to commit to a certain API yet at least. // export {NonError} from './errors/NonError.js'; //# sourceMappingURL=index.js.map