web-ui-pack
Version:
Web package with UI elements
26 lines (25 loc) • 1.3 kB
TypeScript
declare const nestedProperty: {
/** Parse "obj.nestedValue.items[0].id" into array of keys [obj, nestedValues, items, 0, id] */
parsePath(path: string): [string[], boolean[]];
/**
* Sets the value at path of object. If a portion of path doesn’t exist it’s created.
* nestedProperty.set(obj, "value.nestedValue", 1) as obj.value.nestedValue = 1;
* @param object The object to modify.
* @param path The path of the property to set; point `obj.items[0].id` for example
* @param value The value to set.
* @returns pointed same object
*/
set<T extends Record<string, any>>(obj: T, path: string, value: any): T;
/**
* Gets the property value at path of object.
* nestedProperty.get(obj, "nestedValue1.nestVal2") returns value from obj.nestedValue1.nestVal2
* @param object The object to query.
* @param path The path of the property to get; point `obj.items[0].id` for example
* @param out output object. Point empty {} if you want to get extrachecking hasProp (to define if prop undefined and exists)
* @return Returns the resolved value.
*/
get<TObj extends Record<string, any>, TVal>(obj: TObj, path: string, out?: {
hasProp?: boolean;
}): TVal | undefined;
};
export default nestedProperty;