MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / deepMerge

Function deepMerge

apps/site/util/objects.ts:18–37  ·  view source on GitHub ↗
(
  obj1: Obj1,
  obj2: Obj2
)

Source from the content-addressed store, hash-verified

16};
17
18export function deepMerge<Obj1 extends object, Obj2 extends object>(
19 obj1: Obj1,
20 obj2: Obj2
21): Obj1 & Obj2 {
22 const result = { ...obj1 } as Obj1 & Obj2;
23
24 for (const key in obj2) {
25 if (Object.prototype.hasOwnProperty.call(obj2, key)) {
26 if (typeof obj2[key] === 'object' && obj2[key] !== null) {
27 // eslint-disable-next-line @typescript-eslint/no-explicit-any
28 result[key] = deepMerge(result[key] as any, obj2[key] as any);
29 } else {
30 // eslint-disable-next-line @typescript-eslint/no-explicit-any
31 result[key] = obj2[key] as any;
32 }
33 }
34 }
35
36 return result;
37}

Callers 2

loadLocaleDictionaryFunction · 0.90
objects.test.mjsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected