UNPKG

1.66 kBTypeScriptView Raw
1export = set;
2
3// Technically, everything will fall to the last overload,
4// but the first one can be useful for signature help.
5
6/**
7 * @param object The object to set `value` on
8 * @param path The of the property to set.
9 * @param value The value to set on `object[prop]`
10 * @param [options]
11 */
12
13declare function set<T extends object, K extends keyof T>(object: T, path: K, value: T[K], options?: set.Options): void;
14declare function set(object: object, path: set.InputType, value: any, options?: set.Options): void;
15
16declare namespace set {
17 interface Options {
18 /**
19 * Do not split properties that include a `/`.
20 * By default, set-value assumes that properties with a `/` are not intended to be split.
21 * This option allows you to disable default behavior.
22 * Note that this option cannot be used if `options.separator` is set to `/`.
23 * @default true
24 */
25 preservePaths?: boolean | undefined;
26 /**
27 * Custom separator to use for splitting object paths.
28 * @default `.`
29 */
30 separator?: string | undefined;
31 /**
32 * Custom `.split()` function to use.
33 */
34 split?: SplitFunc | undefined;
35 /**
36 * Allows you to update plain object values, instead of overwriting them.
37 * @default `undefined`
38 */
39 merge?: boolean | MergeFunc | undefined;
40 }
41
42 type InputType = string | symbol | ReadonlyArray<string | symbol>;
43
44 type MergeFunc = <TObject, TSource>(object: TObject, source: TSource) => TObject & TSource;
45
46 type SplitFunc = (input: string, options?: Options) => string;
47}