Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samislam/mergerobjects
merge multiple objects works perfectly with typescript
https://github.com/samislam/mergerobjects
Last synced: 1 day ago
JSON representation
merge multiple objects works perfectly with typescript
- Host: GitHub
- URL: https://github.com/samislam/mergerobjects
- Owner: samislam
- Created: 2023-03-24T09:14:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-12T22:40:58.000Z (11 months ago)
- Last Synced: 2024-10-27T09:18:34.317Z (23 days ago)
- Language: TypeScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Quick Start
```ts
import { mergeObjects } from 'mergerobjects'const objA = { a: 'apple', b: 'banana', c: { x: 8, y: 5 } }
const objB = { b: 'Juice', c: { x: 0, v: 3 } }const merged = mergeObjects(objA, objB) // you can provide unlimited arguments...
// { a: 'apple', b: 'Juice', c: { x: 0, v: 3 } }
```Unlike lodash's `_.merge()` function, **mergeObjects** creates a new instance of your object and doesn't mutate your objects.
Regarding deep, or shallow copying; **mergeObjects** makes a shallow copy of your objects, and does not deep clone them. This means that after merging, you'll lose the prototype chain from the end object, as it returns a POJO (Plain Old JavaScript Object).
**mergeObjects** is a simple and a quick utility for merging objects, and it works perfectly with TypeScript for auto completions.
# API Reference:
```
mergeObjects(...sources: object[]) => The merged object
```- If you provide no arguments, an empty object is returned.