Member Junction
    Preparing search index...
    • Deep-merges plain-object layers, EARLIEST first — later layers win per key — into a fresh object, without prototype pollution.

      Merge rules (per key):

      • plain object vs plain object → recursive per-key merge;
      • a plain object over anything else → a deep copy of the incoming object REPLACES;
      • arrays → a shallow copy (slice()) of the incoming array REPLACES;
      • anything else (strings, numbers, booleans, null) → the incoming value REPLACES;
      • undefined incoming values are skipped;
      • __proto__, constructor and prototype keys are skipped at every depth, so untrusted JSON (e.g. a client-supplied override layer) cannot write into Object.prototype.

      Layers that are not plain objects (null, undefined, arrays, scalars) are skipped. Inputs are never mutated.

      Parameters

      • ...layers: readonly unknown[]

        The layers to merge, base first, most specific last

      Returns Record<string, unknown>

      The merged object (an empty object when no layer contributes)

      SafeDeepMerge({ a: { x: 1, y: 2 } }, { a: { y: 3 } });   // { a: { x: 1, y: 3 } }
      SafeDeepMerge({}, JSON.parse('{"__proto__":{"p":1}}')); // {} — Object.prototype untouched