super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
25 lines (24 loc) • 691 B
TypeScript
import { PropertyPath } from '../utils/types';
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned.
*
* @param object - The object to query
* @param path - The path of the property to get
* @param defaultValue - The value returned for undefined resolved values
* @returns The resolved value
*
* @example
* ```ts
* const object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* get(object, 'a[0].b.c');
* // => 3
*
* get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* get(object, 'a.b.c', 'default');
* // => 'default'
* ```
*/
export declare function get<T = any>(object: any, path: PropertyPath, defaultValue?: T): T | undefined;