# @trenskow/merge

> A small library for doing recursive `Object.assign`.

Latest version **0.1.70** (published 2026-10-05) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install @trenskow/merge
pnpm add @trenskow/merge
yarn add @trenskow/merge
bun add @trenskow/merge
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.70 |
| Published | 2026-10-05 |
| First published | 2021-11-15 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kristian Trenskow |
| Maintainers | trenskow |
| Keywords | object, assign, recursive |

## Links

- npm: https://www.npmjs.com/package/@trenskow/merge
- Repository: https://github.com/trenskow/merge
- Homepage: https://github.com/trenskow/merge#readme
- Issues: https://github.com/trenskow/merge/issues
- npm.io page: https://npm.io/package/@trenskow/merge

## Recent versions

- 0.1.70 (latest) — 2026-10-05
- 0.1.69 — 2026-09-21
- 0.1.68 — 2026-09-18
- 0.1.67 — 2026-09-16
- 0.1.66 — 2026-09-16
- 0.1.65 — 2026-09-16
- 0.1.64 — 2026-08-03
- 0.1.63 — 2026-07-27
- 0.1.62 — 2026-07-13
- 0.1.61 — 2026-07-02
- 0.1.60 — 2026-06-25
- 0.1.59 — 2026-06-08
- 0.1.58 — 2026-05-28
- 0.1.57 — 2026-05-19
- 0.1.56 — 2026-05-05
- … 55 more at https://npm.io/package/@trenskow/merge/versions

## README

# @trenskow/merge

A small library for doing recursive `Object.assign`.

## Usage

Below is an example of how to use the package.

````javascript
import merge from '@trenskow/merge';

const myFirstValue = { first: 1, shared: { value: 1 } };
const mySecondValue = { second: 2, shared: { value: 2 } };
const myThirdValue = { third: 3, shared: { value: 3 } };

const myValue = merge(myFirstValue, mySecondValue, myThirdValue);

/*
	myValue is {
		first: 1,
		second: 2,
		third: 3,
		shared: {
			value: 3
		}
	}
*/
````

## How it works

Input values are compared in pairs, so if more than two values are provided, the first two are compared – then the result is compared to the third – and that result is compared to the fourth, etc...

### Rules

The rules for merging the input values is as below.

1) If one of the values is not an object?
	* The second value survives.
2) If both values are an array?
	* An new array is created with the items from the first array and then the values of the second array.
		* The new array survives.
3) Both values are now regarded as objects.
	* An new object with the following keys are created.
		* The properties unique of the first object.
		* The properties which is set on both objects are merged.
		* The keys unique of the second object.
		* The new object survives.

# License

See license in LICENSE.

---
_Source: https://npm.io/package/@trenskow/merge · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
