Skip to content

Commit

Permalink
refactor deepMerge to accomodate instance of browser based custom Obj…
Browse files Browse the repository at this point in the history
…ects using contructors
  • Loading branch information
ThobyV committed Sep 19, 2020
1 parent 38680e7 commit 90c1f8d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ MIT License 2020
const newObj = Object.assign({}, base, config);
if (isObject(base) && isObject(config)) {
for (const i in config) {
if (config[i] == (null || undefined)) {
newObj[i] = config[i];
}
if (Array.isArray(config[i])) {
newObj[i].concat(base[i]);
}
if (isObject(config[i]) && !Array.isArray(config[i])) {
if (!base[i]) {
newObj[i] = Object.assign({}, { [i]: config[i] });
} else {
newObj[i] = deepMerge(base[i], config[i]);
if (
isObject(config[i]) &&
!Array.isArray(config[i]) &&
config[i].constructor === Object
) {
if (!newObj[i]) {
newObj[i] = {};
}
newObj[i] = deepMerge(base[i], config[i]);
}
if (config[i] == (null || undefined)) {
newObj[i] = config[i];
}
}
}
Expand Down

0 comments on commit 90c1f8d

Please sign in to comment.