source: node_modules/es-toolkit/dist/compat/object/get.d.mts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 14.4 KB
Line 
1import { GetFieldType } from '../_internal/GetFieldType.mjs';
2import { PropertyPath } from '../_internal/PropertyPath.mjs';
3
4/**
5 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
6 *
7 * @template TObject
8 * @template TKey
9 * @param {TObject} object - The object to query.
10 * @param {TKey | [TKey]} path - The path of the property to get.
11 * @returns {TObject[TKey]} Returns the resolved value.
12 *
13 * @example
14 * const object = { 'a': [{ 'b': { 'c': 3 } }] };
15 * get(object, 'a[0].b.c');
16 * // => 3
17 */
18declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject, path: TKey | [TKey]): TObject[TKey];
19/**
20 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
21 *
22 * @template TObject
23 * @template TKey
24 * @param {TObject | null | undefined} object - The object to query.
25 * @param {TKey | [TKey]} path - The path of the property to get.
26 * @returns {TObject[TKey] | undefined} Returns the resolved value.
27 *
28 * @example
29 * const object = { 'a': [{ 'b': { 'c': 3 } }] };
30 * get(object, 'a[0].b.c');
31 * // => 3
32 */
33declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject | null | undefined, path: TKey | [TKey]): TObject[TKey] | undefined;
34/**
35 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
36 *
37 * @template TObject
38 * @template TKey
39 * @template TDefault
40 * @param {TObject | null | undefined} object - The object to query.
41 * @param {TKey | [TKey]} path - The path of the property to get.
42 * @param {TDefault} defaultValue - The value returned if the resolved value is undefined.
43 * @returns {Exclude<TObject[TKey], undefined> | TDefault} Returns the resolved value.
44 *
45 * @example
46 * const object = { 'a': [{ 'b': { 'c': 3 } }] };
47 * get(object, 'a[0].b.c', 'default');
48 * // => 3
49 */
50declare function get<TObject extends object, TKey extends keyof TObject, TDefault>(object: TObject | null | undefined, path: TKey | [TKey], defaultValue: TDefault): Exclude<TObject[TKey], undefined> | TDefault;
51/**
52 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
53 *
54 * @template TObject
55 * @template TKey1
56 * @template TKey2
57 * @param {TObject} object - The object to query.
58 * @param {[TKey1, TKey2]} path - The path of the property to get.
59 * @returns {TObject[TKey1][TKey2]} Returns the resolved value.
60 *
61 * @example
62 * const object = { 'a': { 'b': 2 } };
63 * get(object, ['a', 'b']);
64 * // => 2
65 */
66declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1]>(object: TObject, path: [TKey1, TKey2]): TObject[TKey1][TKey2];
67/**
68 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
69 *
70 * @template TObject
71 * @template TKey1
72 * @template TKey2
73 * @param {TObject | null | undefined} object - The object to query.
74 * @param {[TKey1, TKey2]} path - The path of the property to get.
75 * @returns {NonNullable<TObject[TKey1]>[TKey2] | undefined} Returns the resolved value.
76 *
77 * @example
78 * const object = { 'a': { 'b': 2 } };
79 * get(object, ['a', 'b']);
80 * // => 2
81 */
82declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>>(object: TObject | null | undefined, path: [TKey1, TKey2]): NonNullable<TObject[TKey1]>[TKey2] | undefined;
83/**
84 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
85 *
86 * @template TObject
87 * @template TKey1
88 * @template TKey2
89 * @template TDefault
90 * @param {TObject | null | undefined} object - The object to query.
91 * @param {[TKey1, TKey2]} path - The path of the property to get.
92 * @param {TDefault} defaultValue - The value returned if the resolved value is undefined.
93 * @returns {Exclude<NonNullable<TObject[TKey1]>[TKey2], undefined> | TDefault} Returns the resolved value.
94 *
95 * @example
96 * const object = { 'a': { 'b': 2 } };
97 * get(object, ['a', 'b'], 'default');
98 * // => 2
99 */
100declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2], defaultValue: TDefault): Exclude<NonNullable<TObject[TKey1]>[TKey2], undefined> | TDefault;
101/**
102 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
103 *
104 * @template TObject
105 * @template TKey1
106 * @template TKey2
107 * @template TKey3
108 * @param {TObject} object - The object to query.
109 * @param {[TKey1, TKey2, TKey3]} path - The path of the property to get.
110 * @returns {TObject[TKey1][TKey2][TKey3]} Returns the resolved value.
111 *
112 * @example
113 * const object = { 'a': { 'b': { 'c': 3 } } };
114 * get(object, ['a', 'b', 'c']);
115 * // => 3
116 */
117declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2]>(object: TObject, path: [TKey1, TKey2, TKey3]): TObject[TKey1][TKey2][TKey3];
118/**
119 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
120 *
121 * @template TObject
122 * @template TKey1
123 * @template TKey2
124 * @template TKey3
125 * @param {TObject | null | undefined} object - The object to query.
126 * @param {[TKey1, TKey2, TKey3]} path - The path of the property to get.
127 * @returns {NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3] | undefined} Returns the resolved value.
128 *
129 * @example
130 * const object = { 'a': { 'b': { 'c': 3 } } };
131 * get(object, ['a', 'b', 'c']);
132 * // => 3
133 */
134declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3]): NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3] | undefined;
135/**
136 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
137 *
138 * @template TObject
139 * @template TKey1
140 * @template TKey2
141 * @template TKey3
142 * @template TDefault
143 * @param {TObject | null | undefined} object - The object to query.
144 * @param {[TKey1, TKey2, TKey3]} path - The path of the property to get.
145 * @param {TDefault} defaultValue - The value returned if the resolved value is undefined.
146 * @returns {Exclude<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3], undefined> | TDefault} Returns the resolved value.
147 *
148 * @example
149 * const object = { 'a': { 'b': { 'c': 3 } } };
150 * get(object, ['a', 'b', 'c'], 'default');
151 * // => 3
152 */
153declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3], defaultValue: TDefault): Exclude<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3], undefined> | TDefault;
154/**
155 * Gets the value at path of object.
156 *
157 * @template TObject
158 * @template TKey1
159 * @template TKey2
160 * @template TKey3
161 * @template TKey4
162 * @param {TObject} object - The object to query.
163 * @param {[TKey1, TKey2, TKey3, TKey4]} path - The path of the property to get.
164 * @returns {TObject[TKey1][TKey2][TKey3][TKey4]} Returns the resolved value.
165 *
166 * @example
167 * const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
168 * get(object, ['a', 'b', 'c', 'd']);
169 * // => 4
170 */
171declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2], TKey4 extends keyof TObject[TKey1][TKey2][TKey3]>(object: TObject, path: [TKey1, TKey2, TKey3, TKey4]): TObject[TKey1][TKey2][TKey3][TKey4];
172/**
173 * Gets the value at path of object. If the resolved value is undefined, undefined is returned.
174 *
175 * @template TObject
176 * @template TKey1
177 * @template TKey2
178 * @template TKey3
179 * @template TKey4
180 * @param {TObject | null | undefined} object - The object to query.
181 * @param {[TKey1, TKey2, TKey3, TKey4]} path - The path of the property to get.
182 * @returns {NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4] | undefined} Returns the resolved value.
183 *
184 * @example
185 * const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
186 * get(object, ['a', 'b', 'c', 'd']);
187 * // => 4
188 */
189declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4]): NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4] | undefined;
190/**
191 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
192 *
193 * @template TObject
194 * @template TKey1
195 * @template TKey2
196 * @template TKey3
197 * @template TKey4
198 * @template TDefault
199 * @param {TObject | null | undefined} object - The object to query.
200 * @param {[TKey1, TKey2, TKey3, TKey4]} path - The path of the property to get.
201 * @param {TDefault} defaultValue - The value returned if the resolved value is undefined.
202 * @returns {Exclude<NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4], undefined> | TDefault} Returns the resolved value.
203 *
204 * @example
205 * const object = { 'a': { 'b': { 'c': { 'd': 4 } } } };
206 * get(object, ['a', 'b', 'c', 'd'], 'default');
207 * // => 4
208 */
209declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4], defaultValue: TDefault): Exclude<NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4], undefined> | TDefault;
210/**
211 * Gets the value at path of object.
212 *
213 * @template T
214 * @param {Record<number, T>} object - The object to query.
215 * @param {number} path - The path of the property to get.
216 * @returns {T} Returns the resolved value.
217 *
218 * @example
219 * const object = { 0: 'a', 1: 'b', 2: 'c' };
220 * get(object, 1);
221 * // => 'b'
222 */
223declare function get<T>(object: Record<number, T>, path: number): T;
224/**
225 * Gets the value at path of object. If the resolved value is undefined, undefined is returned.
226 *
227 * @template T
228 * @param {Record<number, T> | null | undefined} object - The object to query.
229 * @param {number} path - The path of the property to get.
230 * @returns {T | undefined} Returns the resolved value.
231 *
232 * @example
233 * const object = { 0: 'a', 1: 'b', 2: 'c' };
234 * get(object, 1);
235 * // => 'b'
236 */
237declare function get<T>(object: Record<number, T> | null | undefined, path: number): T | undefined;
238/**
239 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
240 *
241 * @template T
242 * @template TDefault
243 * @param {Record<number, T> | null | undefined} object - The object to query.
244 * @param {number} path - The path of the property to get.
245 * @param {TDefault} defaultValue - The value returned if the resolved value is undefined.
246 * @returns {T | TDefault} Returns the resolved value.
247 *
248 * @example
249 * const object = { 0: 'a', 1: 'b', 2: 'c' };
250 * get(object, 1, 'default');
251 * // => 'b'
252 */
253declare function get<T, TDefault>(object: Record<number, T> | null | undefined, path: number, defaultValue: TDefault): T | TDefault;
254/**
255 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
256 *
257 * @template TDefault
258 * @param {null | undefined} object - The object to query.
259 * @param {PropertyPath} path - The path of the property to get.
260 * @param {TDefault} defaultValue - The value returned if the resolved value is undefined.
261 * @returns {TDefault} Returns the default value.
262 *
263 * @example
264 * get(null, 'a.b.c', 'default');
265 * // => 'default'
266 */
267declare function get<TDefault>(object: null | undefined, path: PropertyPath, defaultValue: TDefault): TDefault;
268/**
269 * Gets the value at path of object. If the resolved value is undefined, undefined is returned.
270 *
271 * @param {null | undefined} object - The object to query.
272 * @param {PropertyPath} path - The path of the property to get.
273 * @returns {undefined} Returns undefined.
274 *
275 * @example
276 * get(null, 'a.b.c');
277 * // => undefined
278 */
279declare function get(object: null | undefined, path: PropertyPath): undefined;
280/**
281 * Gets the value at path of object using type-safe path.
282 *
283 * @template TObject
284 * @template TPath
285 * @param {TObject} data - The object to query.
286 * @param {TPath} path - The path of the property to get.
287 * @returns {string extends TPath ? any : GetFieldType<TObject, TPath>} Returns the resolved value.
288 *
289 * @example
290 * const object = { a: { b: { c: 1 } } };
291 * get(object, 'a.b.c');
292 * // => 1
293 */
294declare function get<TObject, TPath extends string>(data: TObject, path: TPath): string extends TPath ? any : GetFieldType<TObject, TPath>;
295/**
296 * Gets the value at path of object using type-safe path. If the resolved value is undefined, the defaultValue is returned.
297 *
298 * @template TObject
299 * @template TPath
300 * @template TDefault
301 * @param {TObject} data - The object to query.
302 * @param {TPath} path - The path of the property to get.
303 * @param {TDefault} defaultValue - The value returned if the resolved value is undefined.
304 * @returns {Exclude<GetFieldType<TObject, TPath>, null | undefined> | TDefault} Returns the resolved value.
305 *
306 * @example
307 * const object = { a: { b: { c: 1 } } };
308 * get(object, 'a.b.d', 'default');
309 * // => 'default'
310 */
311declare function get<TObject, TPath extends string, TDefault = GetFieldType<TObject, TPath>>(data: TObject, path: TPath, defaultValue: TDefault): Exclude<GetFieldType<TObject, TPath>, null | undefined> | TDefault;
312/**
313 * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned.
314 *
315 * @param {any} object - The object to query.
316 * @param {PropertyPath} path - The path of the property to get.
317 * @param {any} [defaultValue] - The value returned if the resolved value is undefined.
318 * @returns {any} Returns the resolved value.
319 *
320 * @example
321 * const object = { a: { b: { c: 1 } } };
322 * get(object, 'a.b.c', 'default');
323 * // => 1
324 */
325declare function get(object: any, path: PropertyPath, defaultValue?: any): any;
326
327export { get };
Note: See TracBrowser for help on using the repository browser.