https://github.com/webfactory/merge-objects
https://github.com/webfactory/merge-objects
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/webfactory/merge-objects
- Owner: webfactory
- Created: 2025-08-27T14:10:48.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-27T14:26:02.000Z (10 months ago)
- Last Synced: 2025-08-27T23:34:45.568Z (10 months ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mergeObjects Utility
The `mergeObjects` function is a utility for merging multiple objects into a single object, with an option to perform a deep merge. This function is particularly useful for combining configuration settings, state management, or any scenario where you need to consolidate multiple objects while preserving their properties.
## Installation
```
npm install @webfactoryde/merge-objects
```
## Usage
Import the `mergeObjects` function in your module(s) and pass any number of objects:
```javascript
// your module
import mergeObjects from '@webfactoryde/merge-objects';
// Shallow merge:
const obj1 = { a: 1, b: 2 };
const obj2 = { b: 3, c: 4 };
const result = mergeObjects(obj1, obj2);
console.log(result); // Output: { a: 1, b: 3, c: 4 }
// Deep merge
const obj1 = { a: 1, b: { x: 10, y: 20 } };
const obj2 = { b: { y: 30, z: 40 }, c: 4 };
const result = mergeObjects(true, obj1, obj2);
console.log(result); // Output: { a: 1, b: { x: 10, y: 30, z: 40 }, c: 4 }
```