| 1 | import { PropertyPath } from '../_internal/PropertyPath.mjs';
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * Sets the value at the specified path of the given object using a customizer function.
|
|---|
| 5 | * If any part of the path does not exist, it will be created based on the customizer's result.
|
|---|
| 6 | *
|
|---|
| 7 | * The customizer is invoked to produce the objects of the path. If the customizer returns
|
|---|
| 8 | * a value, that value is used for the current path segment. If the customizer returns
|
|---|
| 9 | * `undefined`, the method will create an appropriate object based on the path - an array
|
|---|
| 10 | * if the next path segment is a valid array index, or an object otherwise.
|
|---|
| 11 | *
|
|---|
| 12 | * @template T - The type of the object.
|
|---|
| 13 | * @param {T} object - The object to modify.
|
|---|
| 14 | * @param {PropertyPath} path - The path of the property to set.
|
|---|
| 15 | * @param {any} value - The value to set.
|
|---|
| 16 | * @param {(nsValue: any, key: string, nsObject: T) => any} [customizer] - The function to customize assigned values.
|
|---|
| 17 | * @returns {T} - The modified object.
|
|---|
| 18 | *
|
|---|
| 19 | * @example
|
|---|
| 20 | * // Set a value with a customizer that creates arrays for numeric path segments
|
|---|
| 21 | * const object = {};
|
|---|
| 22 | * setWith(object, '[0][1]', 'a', (value) => Array.isArray(value) ? value : []);
|
|---|
| 23 | * // => { '0': ['a'] }
|
|---|
| 24 | */
|
|---|
| 25 | declare function setWith<T extends object>(object: T, path: PropertyPath, value: any, customizer?: (nsValue: any, key: string, nsObject: T) => any): T;
|
|---|
| 26 | /**
|
|---|
| 27 | * Sets the value at the specified path of the given object using a customizer function.
|
|---|
| 28 | * If any part of the path does not exist, it will be created based on the customizer's result.
|
|---|
| 29 | *
|
|---|
| 30 | * The customizer is invoked to produce the objects of the path. If the customizer returns
|
|---|
| 31 | * a value, that value is used for the current path segment. If the customizer returns
|
|---|
| 32 | * `undefined`, the method will create an appropriate object based on the path - an array
|
|---|
| 33 | * if the next path segment is a valid array index, or an object otherwise.
|
|---|
| 34 | *
|
|---|
| 35 | * @template T - The type of the object.
|
|---|
| 36 | * @template R - The type of the return value.
|
|---|
| 37 | * @param {T} object - The object to modify.
|
|---|
| 38 | * @param {PropertyPath} path - The path of the property to set.
|
|---|
| 39 | * @param {any} value - The value to set.
|
|---|
| 40 | * @param {(nsValue: any, key: string, nsObject: T) => any} [customizer] - The function to customize assigned values.
|
|---|
| 41 | * @returns {R} - The modified object.
|
|---|
| 42 | *
|
|---|
| 43 | * @example
|
|---|
| 44 | * // Set a value with a customizer that creates arrays for numeric path segments
|
|---|
| 45 | * const object = {};
|
|---|
| 46 | * setWith(object, '[0][1]', 'a', (value) => Array.isArray(value) ? value : []);
|
|---|
| 47 | * // => { '0': ['a'] }
|
|---|
| 48 | */
|
|---|
| 49 | declare function setWith<T extends object, R>(object: T, path: PropertyPath, value: any, customizer?: (nsValue: any, key: string, nsObject: T) => any): R;
|
|---|
| 50 |
|
|---|
| 51 | export { setWith };
|
|---|