Skip to content

feat: add custom merge option #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

alanblins
Copy link
Contributor

Hi,
This is extension to allow the library use custom merge function. By default the library jsonMerge uses Object.assign that has some limitations. Example:
Consider the object below:

var object = {
  'a': [{ 'b': 2 }, { 'd': 4 }]
};
 
var other = {
  'a': [{ 'c': 3 }, { 'e': 5 }]
};

The command Object.assign(object, other) won't merge the keys b and d.

{
 "a":
   [
     {"c":3},
     {"e":5}
   ]
}

The lodash.merge function solves that problem:

const _ = require('lodash');
_.merge(object. other);

Output

{ 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }

@karolis-sh
Copy link
Owner

Hi, yeah legit feature, thanks for the PR!

@alanblins alanblins requested a review from karolis-sh December 8, 2023 21:47
@karolis-sh karolis-sh merged commit f868b35 into karolis-sh:main Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants