es-toolkit 1.28.0 → 1.29.0-dev.916

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Finds the index of the last occurrence of a value in an array.
3
+ *
4
+ * This method is similar to `Array.prototype.lastIndexOf`, but it also finds `NaN` values.
5
+ * It uses strict equality (`===`) to compare elements.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {ArrayLike<T> | null | undefined} array - The array to search.
9
+ * @param {T} searchElement - The value to search for.
10
+ * @param {number} [fromIndex] - The index to start the search at.
11
+ * @returns {number} The index (zero-based) of the last occurrence of the value in the array, or `-1` if the value is not found.
12
+ *
13
+ * @example
14
+ * const array = [1, 2, 3, NaN, 1];
15
+ * lastIndexOf(array, 3); // => 4
16
+ * lastIndexOf(array, NaN); // => 3
17
+ */
18
+ declare function lastIndexOf<T>(array: ArrayLike<T> | null | undefined, searchElement: T, fromIndex?: number): number;
19
+
20
+ export { lastIndexOf };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Finds the index of the last occurrence of a value in an array.
3
+ *
4
+ * This method is similar to `Array.prototype.lastIndexOf`, but it also finds `NaN` values.
5
+ * It uses strict equality (`===`) to compare elements.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {ArrayLike<T> | null | undefined} array - The array to search.
9
+ * @param {T} searchElement - The value to search for.
10
+ * @param {number} [fromIndex] - The index to start the search at.
11
+ * @returns {number} The index (zero-based) of the last occurrence of the value in the array, or `-1` if the value is not found.
12
+ *
13
+ * @example
14
+ * const array = [1, 2, 3, NaN, 1];
15
+ * lastIndexOf(array, 3); // => 4
16
+ * lastIndexOf(array, NaN); // => 3
17
+ */
18
+ declare function lastIndexOf<T>(array: ArrayLike<T> | null | undefined, searchElement: T, fromIndex?: number): number;
19
+
20
+ export { lastIndexOf };
@@ -0,0 +1,22 @@
1
+ import { isArrayLike } from '../predicate/isArrayLike.mjs';
2
+
3
+ function lastIndexOf(array, searchElement, fromIndex) {
4
+ if (!isArrayLike(array) || array.length === 0) {
5
+ return -1;
6
+ }
7
+ const length = array.length;
8
+ let index = fromIndex ?? length - 1;
9
+ if (fromIndex != null) {
10
+ index = index < 0 ? Math.max(length + index, 0) : Math.min(index, length - 1);
11
+ }
12
+ if (Number.isNaN(searchElement)) {
13
+ for (let i = index; i >= 0; i--) {
14
+ if (Number.isNaN(array[i])) {
15
+ return i;
16
+ }
17
+ }
18
+ }
19
+ return Array.from(array).lastIndexOf(searchElement, index);
20
+ }
21
+
22
+ export { lastIndexOf };
@@ -104,6 +104,7 @@ export { intersection } from './array/intersection.mjs';
104
104
  export { intersectionBy } from './array/intersectionBy.mjs';
105
105
  export { join } from './array/join.mjs';
106
106
  export { last } from './array/last.mjs';
107
+ export { lastIndexOf } from './array/lastIndexOf.mjs';
107
108
  export { orderBy } from './array/orderBy.mjs';
108
109
  export { sample } from './array/sample.mjs';
109
110
  export { size } from './array/size.mjs';
@@ -150,6 +151,7 @@ export { sum } from './math/sum.mjs';
150
151
  export { sumBy } from './math/sumBy.mjs';
151
152
  export { assignIn, assignIn as extend } from './object/assignIn.mjs';
152
153
  export { cloneDeep } from './object/cloneDeep.mjs';
154
+ export { cloneDeepWith } from './object/cloneDeepWith.mjs';
153
155
  export { defaults } from './object/defaults.mjs';
154
156
  export { fromPairs } from './object/fromPairs.mjs';
155
157
  export { get } from './object/get.mjs';
@@ -104,6 +104,7 @@ export { intersection } from './array/intersection.js';
104
104
  export { intersectionBy } from './array/intersectionBy.js';
105
105
  export { join } from './array/join.js';
106
106
  export { last } from './array/last.js';
107
+ export { lastIndexOf } from './array/lastIndexOf.js';
107
108
  export { orderBy } from './array/orderBy.js';
108
109
  export { sample } from './array/sample.js';
109
110
  export { size } from './array/size.js';
@@ -150,6 +151,7 @@ export { sum } from './math/sum.js';
150
151
  export { sumBy } from './math/sumBy.js';
151
152
  export { assignIn, assignIn as extend } from './object/assignIn.js';
152
153
  export { cloneDeep } from './object/cloneDeep.js';
154
+ export { cloneDeepWith } from './object/cloneDeepWith.js';
153
155
  export { defaults } from './object/defaults.js';
154
156
  export { fromPairs } from './object/fromPairs.js';
155
157
  export { get } from './object/get.js';
@@ -8,7 +8,7 @@ const unary = require('../_chunk/unary-CcTNuC.js');
8
8
  const noop = require('../_chunk/noop-2IwLUk.js');
9
9
  const rangeRight = require('../_chunk/rangeRight-w3WrXN.js');
10
10
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
11
- const toMerged = require('../_chunk/toMerged-CPY8Ug.js');
11
+ const toMerged = require('../_chunk/toMerged-DGFrN7.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-octpoD.js');
13
13
  const isWeakSet$1 = require('../_chunk/isWeakSet-CvIdTA.js');
14
14
  const upperFirst = require('../_chunk/upperFirst-CorAVn.js');
@@ -354,29 +354,39 @@ function matches(source) {
354
354
  };
355
355
  }
356
356
 
357
- function cloneDeep(obj) {
358
- if (typeof obj !== 'object') {
359
- return toMerged.cloneDeep(obj);
360
- }
361
- switch (Object.prototype.toString.call(obj)) {
362
- case isWeakSet$1.numberTag:
363
- case isWeakSet$1.stringTag:
364
- case isWeakSet$1.booleanTag: {
365
- const result = new obj.constructor(obj?.valueOf());
366
- toMerged.copyProperties(result, obj);
367
- return result;
357
+ function cloneDeepWith(obj, cloneValue) {
358
+ return toMerged.cloneDeepWith(obj, (value, key, object, stack) => {
359
+ const cloned = cloneValue?.(value, key, object, stack);
360
+ if (cloned != null) {
361
+ return cloned;
368
362
  }
369
- case isWeakSet$1.argumentsTag: {
370
- const result = {};
371
- toMerged.copyProperties(result, obj);
372
- result.length = obj.length;
373
- result[Symbol.iterator] = obj[Symbol.iterator];
374
- return result;
363
+ if (typeof obj !== 'object') {
364
+ return undefined;
375
365
  }
376
- default: {
377
- return toMerged.cloneDeep(obj);
366
+ switch (Object.prototype.toString.call(obj)) {
367
+ case isWeakSet$1.numberTag:
368
+ case isWeakSet$1.stringTag:
369
+ case isWeakSet$1.booleanTag: {
370
+ const result = new obj.constructor(obj?.valueOf());
371
+ toMerged.copyProperties(result, obj);
372
+ return result;
373
+ }
374
+ case isWeakSet$1.argumentsTag: {
375
+ const result = {};
376
+ toMerged.copyProperties(result, obj);
377
+ result.length = obj.length;
378
+ result[Symbol.iterator] = obj[Symbol.iterator];
379
+ return result;
380
+ }
381
+ default: {
382
+ return undefined;
383
+ }
378
384
  }
379
- }
385
+ });
386
+ }
387
+
388
+ function cloneDeep(obj) {
389
+ return cloneDeepWith(obj);
380
390
  }
381
391
 
382
392
  const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
@@ -979,6 +989,25 @@ function join(array, separator = ',') {
979
989
  return Array.from(array).join(separator);
980
990
  }
981
991
 
992
+ function lastIndexOf(array, searchElement, fromIndex) {
993
+ if (!isArrayLike(array) || array.length === 0) {
994
+ return -1;
995
+ }
996
+ const length = array.length;
997
+ let index = fromIndex ?? length - 1;
998
+ if (fromIndex != null) {
999
+ index = index < 0 ? Math.max(length + index, 0) : Math.min(index, length - 1);
1000
+ }
1001
+ if (Number.isNaN(searchElement)) {
1002
+ for (let i = index; i >= 0; i--) {
1003
+ if (Number.isNaN(array[i])) {
1004
+ return i;
1005
+ }
1006
+ }
1007
+ }
1008
+ return Array.from(array).lastIndexOf(searchElement, index);
1009
+ }
1010
+
982
1011
  function getPriority(a) {
983
1012
  if (typeof a === 'symbol') {
984
1013
  return 1;
@@ -2778,6 +2807,7 @@ exports.ceil = ceil;
2778
2807
  exports.chunk = chunk;
2779
2808
  exports.clamp = clamp;
2780
2809
  exports.cloneDeep = cloneDeep;
2810
+ exports.cloneDeepWith = cloneDeepWith;
2781
2811
  exports.compact = compact;
2782
2812
  exports.concat = concat;
2783
2813
  exports.conforms = conforms;
@@ -2859,6 +2889,7 @@ exports.join = join;
2859
2889
  exports.kebabCase = kebabCase;
2860
2890
  exports.keysIn = keysIn;
2861
2891
  exports.last = last;
2892
+ exports.lastIndexOf = lastIndexOf;
2862
2893
  exports.lowerCase = lowerCase;
2863
2894
  exports.mapKeys = mapKeys;
2864
2895
  exports.mapValues = mapValues;
@@ -105,6 +105,7 @@ export { intersection } from './array/intersection.mjs';
105
105
  export { intersectionBy } from './array/intersectionBy.mjs';
106
106
  export { join } from './array/join.mjs';
107
107
  export { last } from './array/last.mjs';
108
+ export { lastIndexOf } from './array/lastIndexOf.mjs';
108
109
  export { orderBy } from './array/orderBy.mjs';
109
110
  export { sample } from './array/sample.mjs';
110
111
  export { size } from './array/size.mjs';
@@ -151,6 +152,7 @@ export { sum } from './math/sum.mjs';
151
152
  export { sumBy } from './math/sumBy.mjs';
152
153
  export { assignIn, assignIn as extend } from './object/assignIn.mjs';
153
154
  export { cloneDeep } from './object/cloneDeep.mjs';
155
+ export { cloneDeepWith } from './object/cloneDeepWith.mjs';
154
156
  export { defaults } from './object/defaults.mjs';
155
157
  export { fromPairs } from './object/fromPairs.mjs';
156
158
  export { get } from './object/get.mjs';
@@ -1,29 +1,7 @@
1
- import { cloneDeep as cloneDeep$1, copyProperties } from '../../object/cloneDeep.mjs';
2
- import { argumentsTag, booleanTag, stringTag, numberTag } from '../_internal/tags.mjs';
1
+ import { cloneDeepWith } from './cloneDeepWith.mjs';
3
2
 
4
3
  function cloneDeep(obj) {
5
- if (typeof obj !== 'object') {
6
- return cloneDeep$1(obj);
7
- }
8
- switch (Object.prototype.toString.call(obj)) {
9
- case numberTag:
10
- case stringTag:
11
- case booleanTag: {
12
- const result = new obj.constructor(obj?.valueOf());
13
- copyProperties(result, obj);
14
- return result;
15
- }
16
- case argumentsTag: {
17
- const result = {};
18
- copyProperties(result, obj);
19
- result.length = obj.length;
20
- result[Symbol.iterator] = obj[Symbol.iterator];
21
- return result;
22
- }
23
- default: {
24
- return cloneDeep$1(obj);
25
- }
26
- }
4
+ return cloneDeepWith(obj);
27
5
  }
28
6
 
29
7
  export { cloneDeep };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Creates a deep clone of the given object using a customizer function.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to clone.
6
+ * @param {Function} [cloneValue] - A function to customize the cloning process.
7
+ * @returns {T} - A deep clone of the given object.
8
+ *
9
+ * @example
10
+ * // Clone a primitive value
11
+ * const num = 29;
12
+ * const clonedNum = cloneDeepWith(num);
13
+ * console.log(clonedNum); // 29
14
+ * console.log(clonedNum === num); // true
15
+ *
16
+ * @example
17
+ * // Clone an object with a customizer
18
+ * const obj = { a: 1, b: 2 };
19
+ * const clonedObj = cloneDeepWith(obj, (value) => {
20
+ * if (typeof value === 'number') {
21
+ * return value * 2; // Double the number
22
+ * }
23
+ * });
24
+ * console.log(clonedObj); // { a: 2, b: 4 }
25
+ * console.log(clonedObj === obj); // false
26
+ *
27
+ * @example
28
+ * // Clone an array with a customizer
29
+ * const arr = [1, 2, 3];
30
+ * const clonedArr = cloneDeepWith(arr, (value) => {
31
+ * return value + 1; // Increment each value
32
+ * });
33
+ * console.log(clonedArr); // [2, 3, 4]
34
+ * console.log(clonedArr === arr); // false
35
+ */
36
+ declare function cloneDeepWith<T>(obj: T, cloneValue?: (value: any, key: PropertyKey | undefined, object: T | undefined, stack: Map<any, any>) => any): T;
37
+
38
+ export { cloneDeepWith };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Creates a deep clone of the given object using a customizer function.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to clone.
6
+ * @param {Function} [cloneValue] - A function to customize the cloning process.
7
+ * @returns {T} - A deep clone of the given object.
8
+ *
9
+ * @example
10
+ * // Clone a primitive value
11
+ * const num = 29;
12
+ * const clonedNum = cloneDeepWith(num);
13
+ * console.log(clonedNum); // 29
14
+ * console.log(clonedNum === num); // true
15
+ *
16
+ * @example
17
+ * // Clone an object with a customizer
18
+ * const obj = { a: 1, b: 2 };
19
+ * const clonedObj = cloneDeepWith(obj, (value) => {
20
+ * if (typeof value === 'number') {
21
+ * return value * 2; // Double the number
22
+ * }
23
+ * });
24
+ * console.log(clonedObj); // { a: 2, b: 4 }
25
+ * console.log(clonedObj === obj); // false
26
+ *
27
+ * @example
28
+ * // Clone an array with a customizer
29
+ * const arr = [1, 2, 3];
30
+ * const clonedArr = cloneDeepWith(arr, (value) => {
31
+ * return value + 1; // Increment each value
32
+ * });
33
+ * console.log(clonedArr); // [2, 3, 4]
34
+ * console.log(clonedArr === arr); // false
35
+ */
36
+ declare function cloneDeepWith<T>(obj: T, cloneValue?: (value: any, key: PropertyKey | undefined, object: T | undefined, stack: Map<any, any>) => any): T;
37
+
38
+ export { cloneDeepWith };
@@ -0,0 +1,35 @@
1
+ import { cloneDeepWith as cloneDeepWith$1, copyProperties } from '../../object/cloneDeepWith.mjs';
2
+ import { argumentsTag, booleanTag, stringTag, numberTag } from '../_internal/tags.mjs';
3
+
4
+ function cloneDeepWith(obj, cloneValue) {
5
+ return cloneDeepWith$1(obj, (value, key, object, stack) => {
6
+ const cloned = cloneValue?.(value, key, object, stack);
7
+ if (cloned != null) {
8
+ return cloned;
9
+ }
10
+ if (typeof obj !== 'object') {
11
+ return undefined;
12
+ }
13
+ switch (Object.prototype.toString.call(obj)) {
14
+ case numberTag:
15
+ case stringTag:
16
+ case booleanTag: {
17
+ const result = new obj.constructor(obj?.valueOf());
18
+ copyProperties(result, obj);
19
+ return result;
20
+ }
21
+ case argumentsTag: {
22
+ const result = {};
23
+ copyProperties(result, obj);
24
+ result.length = obj.length;
25
+ result[Symbol.iterator] = obj[Symbol.iterator];
26
+ return result;
27
+ }
28
+ default: {
29
+ return undefined;
30
+ }
31
+ }
32
+ });
33
+ }
34
+
35
+ export { cloneDeepWith };
package/dist/index.d.mts CHANGED
@@ -91,6 +91,7 @@ export { sum } from './math/sum.mjs';
91
91
  export { sumBy } from './math/sumBy.mjs';
92
92
  export { clone } from './object/clone.mjs';
93
93
  export { cloneDeep } from './object/cloneDeep.mjs';
94
+ export { cloneDeepWith } from './object/cloneDeepWith.mjs';
94
95
  export { findKey } from './object/findKey.mjs';
95
96
  export { flattenObject } from './object/flattenObject.mjs';
96
97
  export { invert } from './object/invert.mjs';
package/dist/index.d.ts CHANGED
@@ -91,6 +91,7 @@ export { sum } from './math/sum.js';
91
91
  export { sumBy } from './math/sumBy.js';
92
92
  export { clone } from './object/clone.js';
93
93
  export { cloneDeep } from './object/cloneDeep.js';
94
+ export { cloneDeepWith } from './object/cloneDeepWith.js';
94
95
  export { findKey } from './object/findKey.js';
95
96
  export { flattenObject } from './object/flattenObject.js';
96
97
  export { invert } from './object/invert.js';
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ const noop = require('./_chunk/noop-2IwLUk.js');
11
11
  const rangeRight = require('./_chunk/rangeRight-w3WrXN.js');
12
12
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
13
13
  const math_index = require('./math/index.js');
14
- const toMerged = require('./_chunk/toMerged-CPY8Ug.js');
14
+ const toMerged = require('./_chunk/toMerged-DGFrN7.js');
15
15
  const object_index = require('./object/index.js');
16
16
  const isWeakSet = require('./_chunk/isWeakSet-CvIdTA.js');
17
17
  const predicate_index = require('./predicate/index.js');
@@ -118,6 +118,7 @@ exports.round = math_index.round;
118
118
  exports.sumBy = math_index.sumBy;
119
119
  exports.clone = toMerged.clone;
120
120
  exports.cloneDeep = toMerged.cloneDeep;
121
+ exports.cloneDeepWith = toMerged.cloneDeepWith;
121
122
  exports.findKey = toMerged.findKey;
122
123
  exports.flattenObject = toMerged.flattenObject;
123
124
  exports.invert = toMerged.invert;
package/dist/index.mjs CHANGED
@@ -91,6 +91,7 @@ export { sum } from './math/sum.mjs';
91
91
  export { sumBy } from './math/sumBy.mjs';
92
92
  export { clone } from './object/clone.mjs';
93
93
  export { cloneDeep } from './object/cloneDeep.mjs';
94
+ export { cloneDeepWith } from './object/cloneDeepWith.mjs';
94
95
  export { findKey } from './object/findKey.mjs';
95
96
  export { flattenObject } from './object/flattenObject.mjs';
96
97
  export { invert } from './object/invert.mjs';
@@ -1,114 +1,7 @@
1
- import { getSymbols } from '../compat/_internal/getSymbols.mjs';
2
- import { isPrimitive } from '../predicate/isPrimitive.mjs';
3
- import { isTypedArray } from '../predicate/isTypedArray.mjs';
1
+ import { cloneDeepWithImpl } from './cloneDeepWith.mjs';
4
2
 
5
3
  function cloneDeep(obj) {
6
- return cloneDeepImpl(obj);
7
- }
8
- function cloneDeepImpl(obj, stack = new Map()) {
9
- if (isPrimitive(obj)) {
10
- return obj;
11
- }
12
- if (stack.has(obj)) {
13
- return stack.get(obj);
14
- }
15
- if (Array.isArray(obj)) {
16
- const result = new Array(obj.length);
17
- stack.set(obj, result);
18
- for (let i = 0; i < obj.length; i++) {
19
- result[i] = cloneDeepImpl(obj[i], stack);
20
- }
21
- if (Object.hasOwn(obj, 'index')) {
22
- result.index = obj.index;
23
- }
24
- if (Object.hasOwn(obj, 'input')) {
25
- result.input = obj.input;
26
- }
27
- return result;
28
- }
29
- if (obj instanceof Date) {
30
- return new Date(obj.getTime());
31
- }
32
- if (obj instanceof RegExp) {
33
- const result = new RegExp(obj.source, obj.flags);
34
- result.lastIndex = obj.lastIndex;
35
- return result;
36
- }
37
- if (obj instanceof Map) {
38
- const result = new Map();
39
- stack.set(obj, result);
40
- for (const [key, value] of obj) {
41
- result.set(key, cloneDeepImpl(value, stack));
42
- }
43
- return result;
44
- }
45
- if (obj instanceof Set) {
46
- const result = new Set();
47
- stack.set(obj, result);
48
- for (const value of obj) {
49
- result.add(cloneDeepImpl(value, stack));
50
- }
51
- return result;
52
- }
53
- if (typeof Buffer !== 'undefined' && Buffer.isBuffer(obj)) {
54
- return obj.subarray();
55
- }
56
- if (isTypedArray(obj)) {
57
- const result = new (Object.getPrototypeOf(obj).constructor)(obj.length);
58
- stack.set(obj, result);
59
- for (let i = 0; i < obj.length; i++) {
60
- result[i] = cloneDeepImpl(obj[i], stack);
61
- }
62
- return result;
63
- }
64
- if (obj instanceof ArrayBuffer || (typeof SharedArrayBuffer !== 'undefined' && obj instanceof SharedArrayBuffer)) {
65
- return obj.slice(0);
66
- }
67
- if (obj instanceof DataView) {
68
- const result = new DataView(obj.buffer.slice(0), obj.byteOffset, obj.byteLength);
69
- stack.set(obj, result);
70
- copyProperties(result, obj, stack);
71
- return result;
72
- }
73
- if (typeof File !== 'undefined' && obj instanceof File) {
74
- const result = new File([obj], obj.name, { type: obj.type });
75
- stack.set(obj, result);
76
- copyProperties(result, obj, stack);
77
- return result;
78
- }
79
- if (obj instanceof Blob) {
80
- const result = new Blob([obj], { type: obj.type });
81
- stack.set(obj, result);
82
- copyProperties(result, obj, stack);
83
- return result;
84
- }
85
- if (obj instanceof Error) {
86
- const result = new obj.constructor();
87
- stack.set(obj, result);
88
- result.message = obj.message;
89
- result.name = obj.name;
90
- result.stack = obj.stack;
91
- result.cause = obj.cause;
92
- copyProperties(result, obj, stack);
93
- return result;
94
- }
95
- if (typeof obj === 'object' && obj !== null) {
96
- const result = Object.create(Object.getPrototypeOf(obj));
97
- stack.set(obj, result);
98
- copyProperties(result, obj, stack);
99
- return result;
100
- }
101
- return obj;
102
- }
103
- function copyProperties(target, source, stack) {
104
- const keys = [...Object.keys(source), ...getSymbols(source)];
105
- for (let i = 0; i < keys.length; i++) {
106
- const key = keys[i];
107
- const descriptor = Object.getOwnPropertyDescriptor(target, key);
108
- if (descriptor == null || descriptor.writable) {
109
- target[key] = cloneDeepImpl(source[key], stack);
110
- }
111
- }
4
+ return cloneDeepWithImpl(obj, undefined, obj, new Map(), undefined);
112
5
  }
113
6
 
114
- export { cloneDeep, copyProperties };
7
+ export { cloneDeep };
@@ -0,0 +1,43 @@
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 };
@@ -0,0 +1,43 @@
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 };