source: node_modules/es-toolkit/dist/compat/object/result.d.ts

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

Added visualizations

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[a762898]1import { PropertyPath } from '../_internal/PropertyPath.js';
2
3/**
4 * Retrieves the value at a given path of an object.
5 * If the resolved value is a function, it is invoked with the object as its `this` context.
6 * If the value is `undefined`, the `defaultValue` is returned.
7 *
8 * @template T - The type of object.
9 * @template R - The type of the value to return.
10 * @param {T} object - The object to query.
11 * @param {PropertyPath} path - The path of the property to get.
12 * @param {R | ((...args: any[]) => R)} [defaultValue] - The value returned if the resolved value is `undefined`.
13 * @returns {R} - Returns the resolved value.
14 *
15 * @example
16 * const obj = { a: { b: { c: 3 } } };
17 * result(obj, 'a.b.c');
18 * // => 3
19 *
20 * @example
21 * const obj = { a: () => 5 };
22 * result(obj, 'a');
23 * // => 5 (calls the function `a` and returns its result)
24 *
25 * @example
26 * const obj = { a: { b: null } };
27 * result(obj, 'a.b.c', 'default');
28 * // => 'default'
29 *
30 * @example
31 * const obj = { a: { b: { c: 3 } } };
32 * result(obj, 'a.b.d', () => 'default');
33 * // => 'default'
34 */
35declare function result<R>(object: any, path: PropertyPath, defaultValue?: R | ((...args: any[]) => R)): R;
36
37export { result };
Note: See TracBrowser for help on using the repository browser.