https://github.com/john-james-gh/tiny-deep-merge
A tiny utility to deeply merge multiple plain objects. Arrays are overwritten. Zero dependencies.
https://github.com/john-james-gh/tiny-deep-merge
cjs deep-merge esm lite merge minimal object tiny typescript utility
Last synced: about 1 year ago
JSON representation
A tiny utility to deeply merge multiple plain objects. Arrays are overwritten. Zero dependencies.
- Host: GitHub
- URL: https://github.com/john-james-gh/tiny-deep-merge
- Owner: john-james-gh
- License: mit
- Created: 2025-04-13T11:33:06.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-13T13:09:59.000Z (about 1 year ago)
- Last Synced: 2025-04-13T13:19:37.541Z (about 1 year ago)
- Topics: cjs, deep-merge, esm, lite, merge, minimal, object, tiny, typescript, utility
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/tiny-deep-merge
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-deep-merge
> A utility to deeply merge multiple plain objects.
> Arrays are overwritten (not concatenated).
> No options, no magic โ deterministic merges.
---
## ๐ Why use this?
- Deep merge of nested plain objects
- Merges any number of inputs
- Arrays and primitives are **overwritten** by default
- Zero dependencies (404 B minified and gzipped, compared to 723 B for `deepmerge`)
- Fully type-safe (TypeScript inference preserved)
- Does **not** mutate source objects
---
## ๐ฆ Installation
```bash
npm install tiny-deep-merge
# or
pnpm add tiny-deep-merge
# or
yarn add tiny-deep-merge
```
## ๐งช Usage
```javascript
// ES Module
import { merge } from "tiny-deep-merge"
// CommonJS
const { merge } = require("tiny-deep-merge")
const a = { user: { name: "Jess", age: 25 } }
const b = { user: { age: 31, active: true } }
const result = merge(a, b)
// => { user: { name: "Jess", age: 31, active: true } }
```
## โ
Multi-object merge
```javascript
merge({ a: 1 }, { b: 2 }, { c: { nested: true } })
// => { a: 1, b: 2, c: { nested: true } }
```
## ๐งน Arrays are overwritten by default
```javascript
merge({ tags: ["a", "b"] }, { tags: ["c"] })
// => { tags: ["c"] }
```
## ๐ Does not mutate source objects
```javascript
const a = { count: 1 }
const b = { count: 2 }
const result = merge(a, b)
console.log(a) // { count: 1 }
console.log(result) // { count: 2 }
```
## ๐ง Type Safety
```javascript
const merged = merge({ id: 1 }, { name: "Alice" }, { profile: { age: 25 } })
// merged: { id: number, name: string, profile: { age: number } }
```
## ๐คจ What this does not do
- No array concatenation โ arrays are overwritten.
- No merging of class instances, Maps, Sets, or Dates.
- No custom merge strategies.
- No runtime bloat.
---
## ๐ License
MIT @ John James