deepie-merge 1.3.2 → 1.3.3

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 CHANGED
@@ -23,10 +23,12 @@ deepMerge({a: [1], b: [1]}, {a: [2], b: [2]}, {arrayExtend: ["a"]});
23
23
 
24
24
  ## API
25
25
 
26
- ### deepMerge(dst, src, options)
26
+ ### deepMerge(a, b, options)
27
27
 
28
- - `dst` *any*: Destination value
29
- - `src` *any*: Source value
28
+ Deep-merge `b` into `a`.
29
+
30
+ - `a` *any*: Destination value
31
+ - `b` *any*: Source value
30
32
  - `options` *object*:
31
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.
32
34
  - `maxRecursions` *number*: Amount of nesting levels to recurse into. Default: `10`
@@ -1 +1 @@
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,CA8BtK"}
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"}
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ function canExtendArray(key, arrayExtend) {
16
16
  return Array.isArray(arrayExtend) ? arrayExtend.includes(key) : arrayExtend;
17
17
  }
18
18
  function deepMerge(a, b, { arrayExtend = false, maxRecursion = 10 } = { arrayExtend: false, maxRecursion: 10 }) {
19
+ if (maxRecursion === 0) return a;
19
20
  if (Array.isArray(a)) {
20
21
  if (Array.isArray(b)) {
21
22
  return arrayExtend ? extendArrays(a, b) : b;
@@ -25,20 +26,20 @@ function deepMerge(a, b, { arrayExtend = false, maxRecursion = 10 } = { arrayExt
25
26
  } else if (Array.isArray(b)) {
26
27
  return b;
27
28
  }
28
- if (!isObject(b)) return b;
29
- if (maxRecursion === 0) return a;
30
- for (const key of Object.keys(b)) {
31
- const typeA = getType(a[key]);
32
- const typeB = getType(b[key]);
33
- if (typeA !== typeB) {
34
- a[key] = b[key];
35
- } else {
36
- if (typeA === "array" && canExtendArray(key, arrayExtend)) {
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 {
29
+ if (isObject(a) && isObject(b)) {
30
+ for (const key of Object.keys(b)) {
31
+ const typeA = getType(a[key]);
32
+ const typeB = getType(b[key]);
33
+ if (typeA !== typeB) {
41
34
  a[key] = b[key];
35
+ } else {
36
+ if (typeA === "array" && canExtendArray(key, arrayExtend)) {
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
+ }
42
43
  }
43
44
  }
44
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepie-merge",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Yay, another deep merge",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/deepie-merge",
@@ -17,14 +17,14 @@
17
17
  "node": ">=18"
18
18
  },
19
19
  "devDependencies": {
20
- "@types/node": "24.0.14",
20
+ "@types/node": "24.3.0",
21
21
  "eslint": "8.57.0",
22
- "eslint-config-silverwind": "101.4.0",
23
- "typescript": "5.8.3",
24
- "typescript-config-silverwind": "9.0.8",
25
- "updates": "16.4.4",
26
- "versions": "13.1.0",
27
- "vite": "7.0.5",
22
+ "eslint-config-silverwind": "102.0.3",
23
+ "typescript": "5.9.2",
24
+ "typescript-config-silverwind": "10.0.1",
25
+ "updates": "16.6.2",
26
+ "versions": "13.1.1",
27
+ "vite": "7.1.3",
28
28
  "vite-config-silverwind": "5.4.0",
29
29
  "vitest": "3.2.4",
30
30
  "vitest-config-silverwind": "10.2.0"