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)

Functions

f
deepMerge<
T extends Record<PropertyKey, unknown>,
U extends Record<PropertyKey, unknown>,
Options extends DeepMergeOptions = { arrays: "merge"; sets: "merge"; maps: "merge"; }
>
(
record: Readonly<T>,
other: Readonly<U>,
options?: Readonly<Options>
): DeepMerge<T, U, Options>
2 overloads

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

Type Aliases

T
ArrayValueType<T> = T extends Array<infer V> ? V : never

Get array values type

T
DeepMerge<T, U, Options = Record<string, MergingStrategy>> = [T, U] extends [Record<PropertyKey, unknown>, Record<PropertyKey, unknown>] ? Merge<T, U, Options> : T | U

Merge deeply two objects

T
DeepMergeOptions = { arrays?: MergingStrategy; maps?: MergingStrategy; sets?: MergingStrategy; }

Deep merge options

  • arrays: MergingStrategy
    No documentation available
  • maps: MergingStrategy
    No documentation available
  • sets: MergingStrategy
    No documentation available
T
ExpandRecursively<T> = T extends Record<PropertyKey, unknown> ? T extends infer O ? [K in keyof O]: ExpandRecursively<O[K]> : never : T

Force intellisense to expand the typing to hide merging typings

T
MapKeyType<T> = T extends Map<infer K, unknown> ? K : never

Get map values types

T
MapValueType<T> = T extends Map<unknown, infer V> ? V : never

Get map values types

T
Merge<
T,
U,
Options,
X =
MergeRightOmitComplexes<T, U>
& MergeAllRecords<T, U, Options>
& (Options extends { sets: "replace"; } ? PartialByType<U, Set<unknown>> : MergeAllSets<T, U>)
& (Options extends { arrays: "replace"; } ? PartialByType<U, Array<unknown>> : MergeAllArrays<T, U>)
& (Options extends { maps: "replace"; } ? PartialByType<U, Map<unknown, unknown>> : MergeAllMaps<T, U>)
>
= ExpandRecursively<X>

Merge two objects

T
MergeAllArrays<
T,
U,
X = PartialByType<T, Array<unknown>>,
Y = PartialByType<U, Array<unknown>>,
Z = [K in keyof X & keyof Y]: Array<ArrayValueType<X[K]> | ArrayValueType<Y[K]>>
>
= Z

Merge all sets types definitions from keys present in both objects

T
MergeAllMaps<
T,
U,
X = PartialByType<T, Map<unknown, unknown>>,
Y = PartialByType<U, Map<unknown, unknown>>,
Z = [K in keyof X & keyof Y]: Map<
MapKeyType<X[K]> | MapKeyType<Y[K]>,
MapValueType<X[K]> | MapValueType<Y[K]>
>
>
= Z

Merge all sets types definitions from keys present in both objects

T
MergeAllRecords<
T,
U,
Options,
X = PartialByType<T, Record<PropertyKey, unknown>>,
Y = PartialByType<U, Record<PropertyKey, unknown>>,
Z = [K in keyof X & keyof Y]: DeepMerge<X[K], Y[K], Options>
>
= Z

Merge all records types definitions from keys present in both objects

T
MergeAllSets<
T,
U,
X = PartialByType<T, Set<unknown>>,
Y = PartialByType<U, Set<unknown>>,
Z = [K in keyof X & keyof Y]: Set<SetValueType<X[K]> | SetValueType<Y[K]>>
>
= Z

Merge all sets types definitions from keys present in both objects

T
MergeRightOmitComplexes<T, U, X = ObjectXorKeys<T, U> & OmitComplexes<[K in keyof U]: U[K]>> = X

Merge two objects, with left precedence

T
MergingStrategy = "replace" | "merge"

Merging strategy

T
ObjectXorKeys<
T,
U,
X = Omit<T, keyof U> & Omit<U, keyof T>,
Y = [K in keyof X]: X[K]
>
= Y

Object with keys in either T or U but not in both

T
OmitComplexes<T> = Omit<
T,
keyof PartialByType<
T,
Map<unknown, unknown>
| Set<unknown>
| Array<unknown>
| Record<PropertyKey, unknown>
>
>

Exclude map, sets and array from type

T
PartialByType<T, U> = [K in keyof T in keyof T[K] extends U ? K : never]: T[K]

Filter of keys matching a given type

T
SetValueType<T> = T extends Set<infer V> ? V : never

Get set values 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 * as mod from "@std/collections/deep_merge";
or

Import directly with a jsr specifier

import * as mod from "jsr:@std/collections/deep_merge";