Deeply merge 2 or more objects respecting type information.
Installations
npm install deepmerge-ts
Developer
RebeccaStevens
Developer Guide
Module System
ESM
Min. Node Version
>=16.0.0
Typescript Support
Yes
Node Version
20.17.0
NPM Version
10.7.0
Statistics
242 Stars
770 Commits
10 Forks
2 Watching
1 Branches
6 Contributors
Updated on 27 Nov 2024
Bundle Size
5.93 kB
Minified
1.73 kB
Minified + Gzipped
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
67,976,364
Last day
6.7%
222,030
Compared to previous day
Last week
6.2%
1,167,693
Compared to previous week
Last month
9.7%
4,745,569
Compared to previous month
Last year
100.1%
41,649,135
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
64
Donate
Any donations would be much appreciated. 😄
Enterprise Users
deepmerge-ts
is available as part of the Tidelift Subscription.
Tidelift is working with the maintainers of deepmerge-ts
and a growing network of open source maintainers to ensure
your open source software supply chain meets enterprise standards now and into the future.
Learn more.
Installation
npm
1# Install with npm 2npm install deepmerge-ts 3 4# Install with pnpm 5pnpm add deepmerge-ts 6 7# Install with yarn 8yarn add deepmerge-ts 9 10# Install with bun 11bun add deepmerge-ts
jsr
1# Install in a node project 2npx jsr add @rebeccastevens/deepmerge 3 4# Install in a deno project 5deno add jsr:@rebeccastevens/deepmerge 6 7# Install in a bun project 8bunx jsr add @rebeccastevens/deepmerge
Features
- Smart merging - High performance.
- Merged output has correct typing.
- Record merging support.
- Array merging support.
- Map and Set merging support.
- Customized merging.
Usage
Example using default config
1import { deepmerge } from "deepmerge-ts"; 2 3const x = { 4 record: { 5 prop1: "value1", 6 prop2: "value2", 7 }, 8 array: [1, 2, 3], 9 set: new Set([1, 2, 3]), 10 map: new Map([ 11 ["key1", "value1"], 12 ["key2", "value2"], 13 ]), 14}; 15 16const y = { 17 record: { 18 prop1: "changed", 19 prop3: "value3", 20 }, 21 array: [2, 3, 4], 22 set: new Set([2, 3, 4]), 23 map: new Map([ 24 ["key2", "changed"], 25 ["key3", "value3"], 26 ]), 27}; 28 29const z = { 30 record: { 31 prop1: undefined, 32 prop3: undefined, 33 prop2: undefined, 34 prop4: undefined, 35 }, 36 array: undefined, 37 set: undefined, 38 map: undefined, 39}; 40 41const merged = deepmerge(x, y, z); 42 43console.log(merged); 44 45// Prettierfied output: 46// 47// Object { 48// "record": Object { 49// "prop1": "changed", 50// "prop2": "value2", 51// "prop3": "value3", 52// "prop4": undefined, 53// }, 54// "array": Array [1, 2, 3, 2, 3, 4], 55// "set": Set { 1, 2, 3, 4 }, 56// "map": Map { 57// "key1" => "value1", 58// "key2" => "changed", 59// "key3" => "value3", 60// }, 61// }
You can try out this example at codesandbox.io.
Merging into a Target
You can use deepmergeInto
if you want to update a target object with the merge result instead of creating a new
object.
This function is best used with objects that are all of the same type.
Note: If the target object's type differs from the input objects, we'll assert that the target's type has changed
(this is not done automatically with deepmergeIntoCustom
).
Customized the Merging Process
We provide a customizer function for each of our main deepmerge functions: deepmergeCustom
and deepmergeIntoCustom
.
You can use these to customize the details of how values should be merged together.
See deepmerge custom docs for more details.
Performance
We use smart merging instead of the classic merging strategy which some alternative libraries use. This vastly improves performance, both in execution time and memory usage.
Classic Merge (not what we do)
With classic merging, each input is merged with the next input until all inputs are merged.
This strategy has large performance issues when lots of items need to be merged.
Smart Merge (what we do)
With our smart merging, we look ahead to see what can be merged and only merge those things.
In addition to performance improvements, this strategy merges multiple inputs at once; allowing for benefits such as taking averages of the inputs.
API
See API docs.
Stable Version
The latest stable version of the package.
Stable Version
7.1.3
HIGH
1
8.1/10
Summary
Prototype Pollution in deepmerge-ts
Affected Versions
< 4.0.2
Patched Versions
4.0.2
Reason
no binaries found in the repo
Reason
25 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: BSD 3-Clause "New" or "Revised" License: LICENSE:0
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-7q7g-4xm8-89cq
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-pqhp-25j4-6hq9
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/accessibility-alt-text-bot.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/accessibility-alt-text-bot.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/build.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/done-label.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/done-label.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint-js.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/lint-js.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint-knip-dev.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/lint-knip-dev.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint-knip-prod.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/lint-knip-prod.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint-markdown.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/lint-markdown.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint-packages.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/lint-packages.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint-spelling.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/lint-spelling.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/semantic-pr.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/semantic-pr.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/stale.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/stale.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sync-labels.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/sync-labels.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/sync-labels.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/sync-labels.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-js.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/test-js.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-js.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/test-js.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-types.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/test-types.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-types.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/test-types.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/typecheck.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/RebeccaStevens/deepmerge-ts/typecheck.yml/main?enable=pin
- Info: 0 out of 14 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 5 third-party GitHubAction dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/build.yml:1
- Warn: no topLevel permission defined: .github/workflows/done-label.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint-js.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint-knip-dev.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint-knip-prod.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint-markdown.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint-packages.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint-spelling.yml:1
- Warn: topLevel 'contents' permission set to 'write': .github/workflows/release.yml:9
- Warn: no topLevel permission defined: .github/workflows/semantic-pr.yml:1
- Warn: no topLevel permission defined: .github/workflows/stale.yml:1
- Warn: no topLevel permission defined: .github/workflows/test-js.yml:1
- Warn: no topLevel permission defined: .github/workflows/test-types.yml:1
- Warn: no topLevel permission defined: .github/workflows/typecheck.yml:1
- Info: no jobLevel write permissions found
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 18 are checked with a SAST tool
Score
4.4
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to deepmerge-ts
deepmerge
A library for deep (recursive) merging of Javascript objects
@fastify/deepmerge
Merges the enumerable properties of two or more objects deeply.
ts-deepmerge
A TypeScript deep merge function.
@corex/deepmerge
A zero dependency object merger with typescript support and built in common merge utilities.