Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thevxn/object-merge
Small, fast, simple and 0 dependency utility for merging two objects.
https://github.com/thevxn/object-merge
deep-merge deepmerge merge-object merge-objects object-merge object-merging
Last synced: about 1 month ago
JSON representation
Small, fast, simple and 0 dependency utility for merging two objects.
- Host: GitHub
- URL: https://github.com/thevxn/object-merge
- Owner: thevxn
- License: mit
- Created: 2023-05-31T21:44:13.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-06-08T08:33:38.000Z (over 1 year ago)
- Last Synced: 2024-10-12T06:26:30.944Z (2 months ago)
- Topics: deep-merge, deepmerge, merge-object, merge-objects, object-merge, object-merging
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@savla-dev/object-merge
- Size: 371 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# object-merge
Small, fast, simple and 0 dependency utility for merging two objects.
## Install
```bash
npm i @savla-dev/object-merge
```## Usage
```ts
import { merge } from '@savla-dev/object-merge'const object1 = {
foo: 'bar',
baz: [1, 2, 3],
nestedObject: {
also: 'works'
}
}const object2 = {
key: 'value',
baz: [4, 5, 6],
nestedObject: {
also: 'this value overrides the one from object1 due to this object having priority',
anotherKey: 'anotherValue'
}
}// Returns the resultingObject below
merge(object1, object2, {
priorityObject: 'right',
useStructuredClone: true,
mergeArrays: true
})const resultingObject = {
foo: 'bar',
baz: [1, 2, 3, 4, 5, 6],
nestedObject: {
also: 'this value overrides the one from object1 due to this object having priority',
anotherKey: 'anotherValue'
},
key: 'value'
}
```## Options
- priorityObject
- Specifies the object to take priority during merging and overriding values at identical keys.
- `"left" | "right"`
- mergeArrays
- Specifies whether arrays should be merged or overriden by the array from the priorityObject. True by default.
- `boolean`
- useStructuredClone
- Specifies whether to use the structuredClone() function to clone the object that is not priorityObject. True by default. If set to false, the `merge()` function will mutate the object not set as priorityObject.
- `boolean`