deepie-merge 1.2.1 → 1.2.2
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.
- package/dist/index.d.ts +5 -1
- package/dist/index.js +9 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,9 @@ type DeepieMergeOpts = {
|
|
|
5
5
|
/** Maximum recursions to perform. Default: 10. */
|
|
6
6
|
maxRecursion?: number;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type DeepMergeable = {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
} | any[];
|
|
11
|
+
/** deep-merge b int a */
|
|
12
|
+
export declare function deepMerge(a: DeepMergeable, b: DeepMergeable, { arrayExtend, maxRecursion }?: DeepieMergeOpts): DeepMergeable;
|
|
9
13
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -12,8 +12,15 @@ function canExtendArray(key, arrayExtend) {
|
|
|
12
12
|
return Array.isArray(arrayExtend) ? arrayExtend.includes(key) : arrayExtend;
|
|
13
13
|
}
|
|
14
14
|
function deepMerge(a, b, { arrayExtend = false, maxRecursion = 10 } = { arrayExtend: false, maxRecursion: 10 }) {
|
|
15
|
-
if (Array.isArray(a)
|
|
16
|
-
|
|
15
|
+
if (Array.isArray(a)) {
|
|
16
|
+
if (Array.isArray(b)) {
|
|
17
|
+
return arrayExtend ? extendArrays(a, b) : b;
|
|
18
|
+
} else {
|
|
19
|
+
return b;
|
|
20
|
+
}
|
|
21
|
+
} else if (Array.isArray(b)) {
|
|
22
|
+
return b;
|
|
23
|
+
}
|
|
17
24
|
if (!isObject(b))
|
|
18
25
|
return b;
|
|
19
26
|
if (maxRecursion === 0)
|