| [a762898] | 1 | /**
|
|---|
| 2 | * Creates a deep clone of the given object.
|
|---|
| 3 | *
|
|---|
| 4 | * @template T - The type of the object.
|
|---|
| 5 | * @param {T} obj - The object to clone.
|
|---|
| 6 | * @returns {T} - A deep clone of the given object.
|
|---|
| 7 | *
|
|---|
| 8 | * @example
|
|---|
| 9 | * // Clone a primitive values
|
|---|
| 10 | * const num = 29;
|
|---|
| 11 | * const clonedNum = cloneDeep(num);
|
|---|
| 12 | * console.log(clonedNum); // 29
|
|---|
| 13 | * console.log(clonedNum === num); // true
|
|---|
| 14 | *
|
|---|
| 15 | * @example
|
|---|
| 16 | * // Clone an array
|
|---|
| 17 | * const arr = [1, 2, 3];
|
|---|
| 18 | * const clonedArr = cloneDeep(arr);
|
|---|
| 19 | * console.log(clonedArr); // [1, 2, 3]
|
|---|
| 20 | * console.log(clonedArr === arr); // false
|
|---|
| 21 | *
|
|---|
| 22 | * @example
|
|---|
| 23 | * // Clone an array with nested objects
|
|---|
| 24 | * const arr = [1, { a: 1 }, [1, 2, 3]];
|
|---|
| 25 | * const clonedArr = cloneDeep(arr);
|
|---|
| 26 | * arr[1].a = 2;
|
|---|
| 27 | * console.log(arr); // [1, { a: 2 }, [1, 2, 3]]
|
|---|
| 28 | * console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]
|
|---|
| 29 | * console.log(clonedArr === arr); // false
|
|---|
| 30 | *
|
|---|
| 31 | * @example
|
|---|
| 32 | * // Clone an object
|
|---|
| 33 | * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|---|
| 34 | * const clonedObj = cloneDeep(obj);
|
|---|
| 35 | * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|---|
| 36 | * console.log(clonedObj === obj); // false
|
|---|
| 37 | *
|
|---|
| 38 | * @example
|
|---|
| 39 | * // Clone an object with nested objects
|
|---|
| 40 | * const obj = { a: 1, b: { c: 1 } };
|
|---|
| 41 | * const clonedObj = cloneDeep(obj);
|
|---|
| 42 | * obj.b.c = 2;
|
|---|
| 43 | * console.log(obj); // { a: 1, b: { c: 2 } }
|
|---|
| 44 | * console.log(clonedObj); // { a: 1, b: { c: 1 } }
|
|---|
| 45 | * console.log(clonedObj === obj); // false
|
|---|
| 46 | */
|
|---|
| 47 | declare function cloneDeep<T>(obj: T): T;
|
|---|
| 48 |
|
|---|
| 49 | export { cloneDeep };
|
|---|