https://github.com/toddself/deepest-merge
https://github.com/toddself/deepest-merge
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/toddself/deepest-merge
- Owner: toddself
- Created: 2014-02-17T15:51:28.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2016-09-12T21:43:26.000Z (almost 10 years ago)
- Last Synced: 2026-03-25T19:50:42.156Z (3 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# deepestMerge
[](https://travis-ci.org/toddself/deepest-merge)
Deepely merges multiple objects together.
If the two keys are functions, composes a wrapper function which calls each function in line (right most first), passing in the final composed object as the context.
If the two keys are arrays, concatenates them together.
It the two keys are objects, recursively calls itself on those objects.
Else, the right most key "wins" and the key to the "left" is overwritten.
## Installation
`npm install deepest-merge`
## Example
```javascript
> var deepestMerge = require('deepest-merge');
> var test1 = false;
> var test2 = false;
> var src = {a: function(){
test1 = true;
}};
> var src2 = {a: function(){
test2 = true;
}};
> var merged = deepestMerge(src, src2);
> merged.a();
> test1
true
> test2
true
```
-
deepestMerge(arguments) → {object}
-
Merge two objects together recursively, merging any nested objects as well
including arrays and functions.
If two key names match and the values aren't functions or arrays, the "latest"
key wins (right imporant). If the values are functions or arrays, the values
are merged -- either wrapped in a function which calls both functions in a row
supplying the final object as the context, or concatenated together with
Array.concat
Parameters:
Name
Type
Argument
Description
arguments
object
<repeatable>
Objects you'd like to merge together
Returns:
merged object
-
Type
-
object
*generated with [docme](https://github.com/thlorenz/docme)*