@se-oss/deep-merge
v1.0.0
Published
A utility for deep merging objects.
Maintainers
Readme
@se-oss/deep-merge
@se-oss/deep-merge is a utility for deep merging objects.
📦 Installation
npm install @se-oss/deep-mergepnpm
pnpm install @se-oss/deep-mergeyarn
yarn add @se-oss/deep-merge📖 Usage
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)📚 Documentation
For all configuration options, please see the API docs.
🤝 Contributing
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! 🙏
License
MIT © Shahrad Elahi and contributors.
