1 | // tslint:disable:variable-name Describing an API that's defined elsewhere.
|
2 | // tslint:disable:no-any describes the API as best we are able today
|
3 |
|
4 | export {isPath};
|
5 |
|
6 |
|
7 | /**
|
8 | * Returns true if the given string is a structured data path (has dots).
|
9 | *
|
10 | * Example:
|
11 | *
|
12 | * ```
|
13 | * isPath('foo.bar.baz') // true
|
14 | * isPath('foo') // false
|
15 | * ```
|
16 | *
|
17 | * @returns True if the string contained one or more dots
|
18 | */
|
19 | declare function isPath(path: string): boolean;
|
20 |
|
21 | export {root};
|
22 |
|
23 |
|
24 | /**
|
25 | * Returns the root property name for the given path.
|
26 | *
|
27 | * Example:
|
28 | *
|
29 | * ```
|
30 | * root('foo.bar.baz') // 'foo'
|
31 | * root('foo') // 'foo'
|
32 | * ```
|
33 | *
|
34 | * @returns Root property name
|
35 | */
|
36 | declare function root(path: string): string;
|
37 |
|
38 | export {isAncestor};
|
39 |
|
40 |
|
41 | /**
|
42 | * Given `base` is `foo.bar`, `foo` is an ancestor, `foo.bar` is not
|
43 | * Returns true if the given path is an ancestor of the base path.
|
44 | *
|
45 | * Example:
|
46 | *
|
47 | * ```
|
48 | * isAncestor('foo.bar', 'foo') // true
|
49 | * isAncestor('foo.bar', 'foo.bar') // false
|
50 | * isAncestor('foo.bar', 'foo.bar.baz') // false
|
51 | * ```
|
52 | *
|
53 | * @returns True if `path` is an ancestor of `base`.
|
54 | */
|
55 | declare function isAncestor(base: string, path: string): boolean;
|
56 |
|
57 | export {isDescendant};
|
58 |
|
59 |
|
60 | /**
|
61 | * Given `base` is `foo.bar`, `foo.bar.baz` is an descendant
|
62 | *
|
63 | * Example:
|
64 | *
|
65 | * ```
|
66 | * isDescendant('foo.bar', 'foo.bar.baz') // true
|
67 | * isDescendant('foo.bar', 'foo.bar') // false
|
68 | * isDescendant('foo.bar', 'foo') // false
|
69 | * ```
|
70 | *
|
71 | * @returns True if `path` is a descendant of `base`.
|
72 | */
|
73 | declare function isDescendant(base: string, path: string): boolean;
|
74 |
|
75 | export {translate};
|
76 |
|
77 |
|
78 | /**
|
79 | * Replaces a previous base path with a new base path, preserving the
|
80 | * remainder of the path.
|
81 | *
|
82 | * User must ensure `path` has a prefix of `base`.
|
83 | *
|
84 | * Example:
|
85 | *
|
86 | * ```
|
87 | * translate('foo.bar', 'zot', 'foo.bar.baz') // 'zot.baz'
|
88 | * ```
|
89 | *
|
90 | * @returns Translated string
|
91 | */
|
92 | declare function translate(base: string, newBase: string, path: string): string;
|
93 |
|
94 | export {matches};
|
95 |
|
96 |
|
97 | /**
|
98 | * @returns True if `path` is equal to `base`
|
99 | */
|
100 | declare function matches(base: string, path: string): boolean;
|
101 |
|
102 | export {normalize};
|
103 |
|
104 |
|
105 | /**
|
106 | * Converts array-based paths to flattened path. String-based paths
|
107 | * are returned as-is.
|
108 | *
|
109 | * Example:
|
110 | *
|
111 | * ```
|
112 | * normalize(['foo.bar', 0, 'baz']) // 'foo.bar.0.baz'
|
113 | * normalize('foo.bar.0.baz') // 'foo.bar.0.baz'
|
114 | * ```
|
115 | *
|
116 | * @returns Flattened path
|
117 | */
|
118 | declare function normalize(path: string|Array<string|number>): string;
|
119 |
|
120 | export {split};
|
121 |
|
122 |
|
123 | /**
|
124 | * Splits a path into an array of property names. Accepts either arrays
|
125 | * of path parts or strings.
|
126 | *
|
127 | * Example:
|
128 | *
|
129 | * ```
|
130 | * split(['foo.bar', 0, 'baz']) // ['foo', 'bar', '0', 'baz']
|
131 | * split('foo.bar.0.baz') // ['foo', 'bar', '0', 'baz']
|
132 | * ```
|
133 | *
|
134 | * @returns Array of path parts
|
135 | */
|
136 | declare function split(path: string|Array<string|number>): string[];
|
137 |
|
138 | export {get};
|
139 |
|
140 |
|
141 | /**
|
142 | * Reads a value from a path. If any sub-property in the path is `undefined`,
|
143 | * this method returns `undefined` (will never throw.
|
144 | *
|
145 | * @returns Value at path, or `undefined` if the path could not be
|
146 | * fully dereferenced.
|
147 | */
|
148 | declare function get(root: object|null, path: string|Array<string|number>, info?: object|null): any;
|
149 |
|
150 | export {set};
|
151 |
|
152 |
|
153 | /**
|
154 | * Sets a value to a path. If any sub-property in the path is `undefined`,
|
155 | * this method will no-op.
|
156 | *
|
157 | * @returns The normalized version of the input path
|
158 | */
|
159 | declare function set(root: object|null, path: string|Array<string|number>, value: any): string|undefined;
|