A utility for deep merging objects.
npm install @se-oss/deep-merge


!npm bundle size

_@se-oss/deep-merge_ is a utility for deep merging objects.
---
- Installation
- Usage
- Documentation
- Contributing
- License
``bash`
npm install @se-oss/deep-merge
Install using your favorite package manager
pnpm
`bash`
pnpm install @se-oss/deep-merge
yarn
`bash`
yarn add @se-oss/deep-merge
`typescript
import { deepMerge } from '@se-oss/deep-merge';
const obj1 = { a: 1, b: { c: 2 }, d: [1, 2] };
const obj2 = { b: { e: 3 }, d: [3, 4], f: 5 };
deepMerge(obj1, obj2);
// => { a: 1, b: { c: 2, e: 3 }, d: [3, 4], f: 5 } (arrays are replaced by default)
deepMerge(obj1, obj2, { mergeArrays: true });
// => { a: 1, b: { c: 2, e: 3 }, d: [1, 2, 3, 4], f: 5 } (arrays are concatenated)
const obj3 = { date: new Date('2023-01-01') };
const obj4 = { date: new Date('2024-01-01'), other: 'value' };
deepMerge(obj3, obj4);
// => { date: [Date object from obj4], other: 'value' } (Date object is replaced)
``
For all configuration options, please see the API docs.
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.
Thanks again for your support, it is much appreciated! 🙏
MIT © Shahrad Elahi and contributors.