std/collections/deep_merge.ts

Deno standard library
Go to Latest
function deepMerge
import { deepMerge } from "https://deno.land/std@0.147.0/collections/deep_merge.ts?s=deepMerge";

Merges the two given Records, recursively merging any nested Records with the second collection overriding the first in case of conflict

For arrays, maps and sets, a merging strategy can be specified to either "replace" values, or "merge" them instead. Use "includeNonEnumerable" option to include non enumerable properties too.

Example:

import { deepMerge } from "https://deno.land/std@0.147.0/collections/deep_merge.ts";
import { assertEquals } from "https://deno.land/std@0.147.0/testing/asserts.ts";

const a = {foo: true}
const b = {foo: {bar: true}}

assertEquals(deepMerge(a, b), {foo: {bar: true}});

Type Parameters

T extends Record<PropertyKey, unknown>[src]

Parameters

record: Partial<Readonly<T>>[src]
other: Partial<Readonly<T>>[src]
optional
options: Readonly<DeepMergeOptions>
[src]

Type Parameters

T extends Record<PropertyKey, unknown>[src]
U extends Record<PropertyKey, unknown>[src]
Options extends DeepMergeOptions[src]

Parameters

record: Readonly<T>[src]
other: Readonly<U>[src]
optional
options: Readonly<Options>
[src]

Returns

DeepMerge<T, U, Options>[src]

Type Parameters

T extends Record<PropertyKey, unknown>[src]
U extends Record<PropertyKey, unknown>[src]
optional
Options extends DeepMergeOptions = { arrays: "merge"; sets: "merge"; maps: "merge"; }
[src]

Parameters

record: Readonly<T>[src]
other: Readonly<U>[src]
optional
options: Readonly<Options>
[src]

Returns

DeepMerge<T, U, Options>[src]