1 | var assignMergeValue = require('./_assignMergeValue'),
|
2 | cloneBuffer = require('./_cloneBuffer'),
|
3 | cloneTypedArray = require('./_cloneTypedArray'),
|
4 | copyArray = require('./_copyArray'),
|
5 | initCloneObject = require('./_initCloneObject'),
|
6 | isArguments = require('./isArguments'),
|
7 | isArray = require('./isArray'),
|
8 | isArrayLikeObject = require('./isArrayLikeObject'),
|
9 | isBuffer = require('./isBuffer'),
|
10 | isFunction = require('./isFunction'),
|
11 | isObject = require('./isObject'),
|
12 | isPlainObject = require('./isPlainObject'),
|
13 | isTypedArray = require('./isTypedArray'),
|
14 | toPlainObject = require('./toPlainObject');
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
|
32 | var objValue = object[key],
|
33 | srcValue = source[key],
|
34 | stacked = stack.get(srcValue);
|
35 |
|
36 | if (stacked) {
|
37 | assignMergeValue(object, key, stacked);
|
38 | return;
|
39 | }
|
40 | var newValue = customizer
|
41 | ? customizer(objValue, srcValue, (key + ''), object, source, stack)
|
42 | : undefined;
|
43 |
|
44 | var isCommon = newValue === undefined;
|
45 |
|
46 | if (isCommon) {
|
47 | var isArr = isArray(srcValue),
|
48 | isBuff = !isArr && isBuffer(srcValue),
|
49 | isTyped = !isArr && !isBuff && isTypedArray(srcValue);
|
50 |
|
51 | newValue = srcValue;
|
52 | if (isArr || isBuff || isTyped) {
|
53 | if (isArray(objValue)) {
|
54 | newValue = objValue;
|
55 | }
|
56 | else if (isArrayLikeObject(objValue)) {
|
57 | newValue = copyArray(objValue);
|
58 | }
|
59 | else if (isBuff) {
|
60 | isCommon = false;
|
61 | newValue = cloneBuffer(srcValue, true);
|
62 | }
|
63 | else if (isTyped) {
|
64 | isCommon = false;
|
65 | newValue = cloneTypedArray(srcValue, true);
|
66 | }
|
67 | else {
|
68 | newValue = [];
|
69 | }
|
70 | }
|
71 | else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
72 | newValue = objValue;
|
73 | if (isArguments(objValue)) {
|
74 | newValue = toPlainObject(objValue);
|
75 | }
|
76 | else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
|
77 | newValue = initCloneObject(srcValue);
|
78 | }
|
79 | }
|
80 | else {
|
81 | isCommon = false;
|
82 | }
|
83 | }
|
84 | if (isCommon) {
|
85 |
|
86 | stack.set(srcValue, newValue);
|
87 | mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
|
88 | stack['delete'](srcValue);
|
89 | }
|
90 | assignMergeValue(object, key, newValue);
|
91 | }
|
92 |
|
93 | module.exports = baseMergeDeep;
|