deepie-merge 1.3.3 → 1.3.6
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/README.md +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +13 -21
- package/package.json +12 -12
- package/dist/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -31,6 +31,6 @@ Deep-merge `b` into `a`.
|
|
|
31
31
|
- `b` *any*: Source value
|
|
32
32
|
- `options` *object*:
|
|
33
33
|
- `arrayExtend` *boolean* or *string[]*: Whether to extend arrays instead of replacing them. When passed a string array, it will only extend the object keys provided in that array.
|
|
34
|
-
- `maxRecursions` *number*: Amount of nesting levels to recurse into. Default: `
|
|
34
|
+
- `maxRecursions` *number*: Amount of nesting levels to recurse into. Default: `20`
|
|
35
35
|
|
|
36
36
|
© [silverwind](https://github.com/silverwind), distributed under BSD licence
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type ArrayExtend = boolean | string
|
|
1
|
+
type ArrayExtend = boolean | Array<string>;
|
|
2
2
|
type DeepieMergeOpts = {
|
|
3
3
|
/** Either a boolean or a array of property keys to allow extension. Default: false */
|
|
4
4
|
arrayExtend?: ArrayExtend;
|
|
@@ -7,8 +7,7 @@ type DeepieMergeOpts = {
|
|
|
7
7
|
};
|
|
8
8
|
type DeepMergeable = {
|
|
9
9
|
[key: string]: any;
|
|
10
|
-
} | any
|
|
11
|
-
/** deep-merge b
|
|
10
|
+
} | Array<any>;
|
|
11
|
+
/** deep-merge b into a */
|
|
12
12
|
export declare function deepMerge<T extends DeepMergeable>(a: T, b: any, { arrayExtend, maxRecursion }?: DeepieMergeOpts): T;
|
|
13
13
|
export {};
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,45 +1,37 @@
|
|
|
1
1
|
function isObject(obj) {
|
|
2
2
|
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
3
3
|
}
|
|
4
|
-
function extendArrays(a, b) {
|
|
5
|
-
return uniq([...a, ...b]);
|
|
6
|
-
}
|
|
7
|
-
function uniq(arr) {
|
|
8
|
-
return Array.from(new Set(arr));
|
|
9
|
-
}
|
|
10
4
|
function getType(obj) {
|
|
11
5
|
if (isObject(obj)) return "object";
|
|
12
6
|
if (Array.isArray(obj)) return "array";
|
|
13
7
|
return typeof obj;
|
|
14
8
|
}
|
|
15
|
-
function
|
|
16
|
-
return
|
|
9
|
+
function deepMerge(a, b, { arrayExtend = false, maxRecursion = 20 } = { arrayExtend: false, maxRecursion: 10 }) {
|
|
10
|
+
return merge(a, b, arrayExtend, maxRecursion);
|
|
17
11
|
}
|
|
18
|
-
function
|
|
12
|
+
function merge(a, b, arrayExtend, maxRecursion) {
|
|
19
13
|
if (maxRecursion === 0) return a;
|
|
20
14
|
if (Array.isArray(a)) {
|
|
21
15
|
if (Array.isArray(b)) {
|
|
22
|
-
return arrayExtend ?
|
|
23
|
-
} else {
|
|
24
|
-
return b;
|
|
16
|
+
return arrayExtend ? Array.from(/* @__PURE__ */ new Set([...a, ...b])) : b;
|
|
25
17
|
}
|
|
26
|
-
} else if (Array.isArray(b)) {
|
|
27
18
|
return b;
|
|
28
19
|
}
|
|
20
|
+
if (Array.isArray(b)) return b;
|
|
29
21
|
if (isObject(a) && isObject(b)) {
|
|
30
|
-
|
|
22
|
+
const keys = Object.keys(b);
|
|
23
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
24
|
+
const key = keys[i];
|
|
31
25
|
const typeA = getType(a[key]);
|
|
32
26
|
const typeB = getType(b[key]);
|
|
33
27
|
if (typeA !== typeB) {
|
|
34
28
|
a[key] = b[key];
|
|
29
|
+
} else if (typeA === "array" && (Array.isArray(arrayExtend) ? arrayExtend.includes(key) : arrayExtend)) {
|
|
30
|
+
a[key] = Array.from(/* @__PURE__ */ new Set([...a[key], ...b[key]]));
|
|
31
|
+
} else if (typeA === "object") {
|
|
32
|
+
a[key] = merge(a[key], b[key], arrayExtend, maxRecursion - 1);
|
|
35
33
|
} else {
|
|
36
|
-
|
|
37
|
-
a[key] = extendArrays(a[key], b[key]);
|
|
38
|
-
} else if (typeA === "object") {
|
|
39
|
-
a[key] = deepMerge(a[key], b[key], { arrayExtend, maxRecursion: maxRecursion - 1 });
|
|
40
|
-
} else {
|
|
41
|
-
a[key] = b[key];
|
|
42
|
-
}
|
|
34
|
+
a[key] = b[key];
|
|
43
35
|
}
|
|
44
36
|
}
|
|
45
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepie-merge",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Yay, another deep merge",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": "silverwind/deepie-merge",
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"node": ">=18"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@types/node": "
|
|
21
|
-
"eslint": "
|
|
22
|
-
"eslint-config-silverwind": "
|
|
23
|
-
"typescript": "5.9.
|
|
24
|
-
"typescript-config-silverwind": "
|
|
25
|
-
"updates": "
|
|
26
|
-
"versions": "
|
|
27
|
-
"vite": "7.1
|
|
28
|
-
"vite-config-silverwind": "
|
|
29
|
-
"vitest": "
|
|
30
|
-
"vitest-config-silverwind": "10.
|
|
20
|
+
"@types/node": "25.2.0",
|
|
21
|
+
"eslint": "9.39.2",
|
|
22
|
+
"eslint-config-silverwind": "120.0.0",
|
|
23
|
+
"typescript": "5.9.3",
|
|
24
|
+
"typescript-config-silverwind": "14.0.0",
|
|
25
|
+
"updates": "17.1.0",
|
|
26
|
+
"versions": "14.1.0",
|
|
27
|
+
"vite": "7.3.1",
|
|
28
|
+
"vite-config-silverwind": "6.0.9",
|
|
29
|
+
"vitest": "4.0.18",
|
|
30
|
+
"vitest-config-silverwind": "10.6.1"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC;AAEtC,KAAK,eAAe,GAAG;IACrB,sFAAsF;IACtF,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAA;AAED,KAAK,aAAa,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,GAAG,GAAG,EAAE,CAAC;AAwBlD,yBAAyB;AACzB,wBAAgB,SAAS,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAC,WAAmB,EAAE,YAAiB,EAAC,GAAE,eAAwD,GAAG,CAAC,CAgCtK"}
|