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: readonlyunknown[]
The layers to merge, base first, most specific last
Returns Record<string,unknown>
The merged object (an empty object when no layer contributes)
Deep-merges plain-object layers, EARLIEST first — later layers win per key — into a fresh object, without prototype pollution.
Merge rules (per key):
slice()) of the incoming array REPLACES;null) → the incoming value REPLACES;undefinedincoming values are skipped;__proto__,constructorandprototypekeys are skipped at every depth, so untrusted JSON (e.g. a client-supplied override layer) cannot write intoObject.prototype.Layers that are not plain objects (
null,undefined, arrays, scalars) are skipped. Inputs are never mutated.