UNPKG

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