From 0b23f28e1eb2bb3af78ca24d5fe3f15da688af44 Mon Sep 17 00:00:00 2001 From: Hafsteinn Date: Tue, 6 Oct 2020 12:48:22 +0200 Subject: [PATCH] #185 add a util function customMergeIgnoreEmptyValues for handyness --- index.js | 4 ++++ test/merge.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f8d6af2..0d8d622 100644 --- a/index.js +++ b/index.js @@ -103,4 +103,8 @@ deepmerge.all = function deepmergeAll(array, options) { }, {}) } +deepmerge.customMergeIgnoreEmptyValues = (key, target, source) => !target || target === '' + ? () => source + : () => target; + module.exports = deepmerge diff --git a/test/merge.js b/test/merge.js index 662408e..955d21d 100644 --- a/test/merge.js +++ b/test/merge.js @@ -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'}} })