| 1 | import { cloneDeepWith as cloneDeepWith$1, copyProperties } from '../../object/cloneDeepWith.mjs';
|
|---|
| 2 | import { getTag } from '../_internal/getTag.mjs';
|
|---|
| 3 | import { objectTag, argumentsTag, booleanTag, stringTag, numberTag } from '../_internal/tags.mjs';
|
|---|
| 4 |
|
|---|
| 5 | function cloneDeepWith(obj, customizer) {
|
|---|
| 6 | return cloneDeepWith$1(obj, (value, key, object, stack) => {
|
|---|
| 7 | const cloned = customizer?.(value, key, object, stack);
|
|---|
| 8 | if (cloned !== undefined) {
|
|---|
| 9 | return cloned;
|
|---|
| 10 | }
|
|---|
| 11 | if (typeof obj !== 'object') {
|
|---|
| 12 | return undefined;
|
|---|
| 13 | }
|
|---|
| 14 | if (getTag(obj) === objectTag && typeof obj.constructor !== 'function') {
|
|---|
| 15 | const result = {};
|
|---|
| 16 | stack.set(obj, result);
|
|---|
| 17 | copyProperties(result, obj, object, stack);
|
|---|
| 18 | return result;
|
|---|
| 19 | }
|
|---|
| 20 | switch (Object.prototype.toString.call(obj)) {
|
|---|
| 21 | case numberTag:
|
|---|
| 22 | case stringTag:
|
|---|
| 23 | case booleanTag: {
|
|---|
| 24 | const result = new obj.constructor(obj?.valueOf());
|
|---|
| 25 | copyProperties(result, obj);
|
|---|
| 26 | return result;
|
|---|
| 27 | }
|
|---|
| 28 | case argumentsTag: {
|
|---|
| 29 | const result = {};
|
|---|
| 30 | copyProperties(result, obj);
|
|---|
| 31 | result.length = obj.length;
|
|---|
| 32 | result[Symbol.iterator] = obj[Symbol.iterator];
|
|---|
| 33 | return result;
|
|---|
| 34 | }
|
|---|
| 35 | default: {
|
|---|
| 36 | return undefined;
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | });
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | export { cloneDeepWith };
|
|---|