UNPKG

super-utils-plus

Version:

A superior alternative to Lodash with improved performance, TypeScript support, and developer experience

24 lines (23 loc) 776 B
import { PropertyPath } from '../utils/types'; /** * Sets the value at path of object. If a portion of path doesn't exist, it's created. * Arrays are created for missing index properties while objects are created for all * other missing properties. * * @param object - The object to modify * @param path - The path of the property to set * @param value - The value to set * @returns The modified object * * @example * ```ts * const object = { 'a': [{ 'b': { 'c': 3 } }] }; * * set(object, 'a[0].b.c', 4); * // => { 'a': [{ 'b': { 'c': 4 } }] } * * set(object, ['x', '0', 'y', 'z'], 5); * // => { 'a': [{ 'b': { 'c': 4 } }], 'x': [{ 'y': { 'z': 5 } }] } * ``` */ export declare function set<T extends object, V>(object: T, path: PropertyPath, value: V): T;