Skip to main content

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Downloads1/wk
Published2 years ago (0.215.0)
function deepMerge
deepMerge<T extends Record<PropertyKey, unknown>>(
record: Partial<Readonly<T>>,
other: Partial<Readonly<T>>,
options?: Readonly<DeepMergeOptions>
): T

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.

Examples

Example 1

import { deepMerge } from "@std/collections/deep_merge";
import { assertEquals } from "@std/assert/assert_equals";

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

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

Type Parameters

T extends Record<PropertyKey, unknown>

Parameters

record: Partial<Readonly<T>>
other: Partial<Readonly<T>>
optional
options: Readonly<DeepMergeOptions>

Return Type

deepMerge<
T extends Record<PropertyKey, unknown>,
U extends Record<PropertyKey, unknown>,
Options extends DeepMergeOptions
>
(
record: Readonly<T>,
other: Readonly<U>,
options?: Readonly<Options>
): DeepMerge<T, U, Options>

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.

Examples

Example 1

import { deepMerge } from "@std/collections/deep_merge";
import { assertEquals } from "@std/assert/assert_equals";

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

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

Type Parameters

T extends Record<PropertyKey, unknown>
U extends Record<PropertyKey, unknown>

Parameters

record: Readonly<T>
other: Readonly<U>
optional
options: Readonly<Options>

Return Type

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/collections

Import symbol

import { deepMerge } from "@std/collections";
or

Import directly with a jsr specifier

import { deepMerge } from "jsr:@std/collections";