| [a762898] | 1 | /**
|
|---|
| 2 | * Deeply clones the given object.
|
|---|
| 3 | *
|
|---|
| 4 | * You can customize the deep cloning process using the `cloneValue` function.
|
|---|
| 5 | * The function takes the current value `value`, the property name `key`, and the entire object `obj` as arguments.
|
|---|
| 6 | * If the function returns a value, that value is used;
|
|---|
| 7 | * if it returns `undefined`, the default cloning method is used.
|
|---|
| 8 | *
|
|---|
| 9 | * @template T - The type of the object.
|
|---|
| 10 | * @param {T} obj - The object to clone.
|
|---|
| 11 | * @param {Function} [cloneValue] - A function to customize the cloning process.
|
|---|
| 12 | * @returns {T} - A deep clone of the given object.
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * // Clone a primitive value
|
|---|
| 16 | * const num = 29;
|
|---|
| 17 | * const clonedNum = cloneDeepWith(num);
|
|---|
| 18 | * console.log(clonedNum); // 29
|
|---|
| 19 | * console.log(clonedNum === num); // true
|
|---|
| 20 | *
|
|---|
| 21 | * @example
|
|---|
| 22 | * // Clone an object with a customizer
|
|---|
| 23 | * const obj = { a: 1, b: 2 };
|
|---|
| 24 | * const clonedObj = cloneDeepWith(obj, (value) => {
|
|---|
| 25 | * if (typeof value === 'number') {
|
|---|
| 26 | * return value * 2; // Double the number
|
|---|
| 27 | * }
|
|---|
| 28 | * });
|
|---|
| 29 | * console.log(clonedObj); // { a: 2, b: 4 }
|
|---|
| 30 | * console.log(clonedObj === obj); // false
|
|---|
| 31 | *
|
|---|
| 32 | * @example
|
|---|
| 33 | * // Clone an array with a customizer
|
|---|
| 34 | * const arr = [1, 2, 3];
|
|---|
| 35 | * const clonedArr = cloneDeepWith(arr, (value) => {
|
|---|
| 36 | * return value + 1; // Increment each value
|
|---|
| 37 | * });
|
|---|
| 38 | * console.log(clonedArr); // [2, 3, 4]
|
|---|
| 39 | * console.log(clonedArr === arr); // false
|
|---|
| 40 | */
|
|---|
| 41 | declare function cloneDeepWith<T>(obj: T, cloneValue: (value: any, key: PropertyKey | undefined, obj: T, stack: Map<any, any>) => any): T;
|
|---|
| 42 |
|
|---|
| 43 | export { cloneDeepWith };
|
|---|