deepest-merge

1.0.0 • Public • Published

deepestMerge

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

> 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

Source:
Returns:

merged object

Type
object

generated with docme

Package Sidebar

Install

npm i deepest-merge

Weekly Downloads

169

Version

1.0.0

License

MIT

Last publish

Collaborators

  • toddself