Skip to content

Commit

Permalink
TehShrike#185 add a util function customMergeIgnoreEmptyValues for ha…
Browse files Browse the repository at this point in the history
…ndyness
  • Loading branch information
Hafsteinn-Ingason-Tidal committed Oct 6, 2020
1 parent 396e085 commit 0b23f28
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ deepmerge.all = function deepmergeAll(array, options) {
}, {})
}

deepmerge.customMergeIgnoreEmptyValues = (key, target, source) => !target || target === ''
? () => source
: () => target;

module.exports = deepmerge
2 changes: 1 addition & 1 deletion test/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ test('customMerge without overwriting with null or empty string', function(t) {
var target = { very: { nested: { thing: 'derp' } } };

var res = merge(target, src, {
customMerge: (key, target, source) => !target || target === '' ? () => source : () => target,
customMerge: merge.customMergeIgnoreEmptyValues,
});

t.deepEqual(res, { someNewVariable: 'herp',very: {nested: { thing: 'derp'}} })
Expand Down

0 comments on commit 0b23f28

Please sign in to comment.