ky
Version:
Tiny and elegant HTTP client based on the Fetch API
38 lines (32 loc) • 2.11 kB
TypeScript
import type { KyHeadersInit, Options } from '../types/options.js';
import type { Hooks, NormalizedHooks } from '../types/hooks.js';
/**
Wraps a value so that `ky.extend()` will replace the parent value instead of merging with it. Works with hooks, headers, search parameters, context, and any other deep-merged option.
Inside the `json` option, which holds your own data, use it only where it replaces an inherited value. Ky does not look for it anywhere else there. The `context` option is merged shallowly, so only a wrapper around the whole `context` is supported.
By default, `.extend()` deep-merges options with the parent instance: hooks get appended, headers get merged, and search parameters get accumulated. Use `replaceOption` when you want to fully replace a merged property instead.
@example
```
import ky, {replaceOption} from 'ky';
const base = ky.create({
hooks: {beforeRequest: [addAuth, addTracking]},
});
// Replaces instead of appending
const extended = base.extend({
hooks: replaceOption({beforeRequest: [onlyThis]}),
});
// hooks.beforeRequest is now [onlyThis], not [addAuth, addTracking, onlyThis]
```
*/
export declare const replaceOption: <T>(value: T) => T;
export declare const validateAndMerge: (...sources: Array<Partial<Options> | undefined>) => Partial<Options>;
export declare const mergeHeaders: (source1?: KyHeadersInit, source2?: KyHeadersInit) => Headers;
export declare const cloneShallow: <T>(value: T) => T;
export declare const cloneSearchParameters: <T>(value: T) => T;
export declare const cloneDeep: <T>(value: T, seen?: WeakMap<Record<string, unknown> | unknown[], unknown>) => T;
export declare const mergeHeaderContainers: (source1: KyHeadersInit, source2: KyHeadersInit) => Record<string, string | undefined>;
export declare const mergeHooks: (original?: Hooks, incoming?: Hooks) => NormalizedHooks;
export declare const deletedParametersSymbol: unique symbol;
export type MarkedSearchParameters = URLSearchParams & {
[deletedParametersSymbol]?: Set<string>;
};
export declare const deepMerge: <T>(...sources: Array<Partial<T> | undefined>) => T;