From 971f5e6f71b6ba655db6b23fde66fbc963b876d0 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Thu, 5 Nov 2020 21:01:03 -0700 Subject: [PATCH] merge with target, not clone with target... --- index.js | 2 +- test/merge.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 8d3d025..fdb44ff 100644 --- a/index.js +++ b/index.js @@ -57,7 +57,7 @@ function propertyIsUnsafe(target, key) { // Retrieves either a new object or the appropriate target object to mutate. function getDestinationObject(target, options) { - if (options && !!options.cloneWithTarget) { + if (options && !!options.mergeWithTarget) { return Array.isArray(target) ? firstArrayEntry(target) : target } diff --git a/test/merge.js b/test/merge.js index f0ebb25..c37b1fc 100644 --- a/test/merge.js +++ b/test/merge.js @@ -1,36 +1,36 @@ var merge = require('../') var test = require('tape') -test('result should retain target type information when cloneWithTarget set to true', function(t) { +test('result should retain target type information when mergeWithTarget set to true', function(t) { var src = { key1: 'value1', key2: 'value2' } class CustomType {} var target = new CustomType() - var res = merge(target, src, {cloneWithTarget: true}) + var res = merge(target, src, {mergeWithTarget: true}) t.not(src instanceof CustomType) t.assert(target instanceof CustomType) t.assert(res instanceof CustomType) t.end() }) -test('modify target object if cloneWithTarget set to true', function(t) { +test('modify target object if mergeWithTarget set to true', function(t) { var src = { key1: 'value1', key2: 'value2' } var target = { key3: 'value3'} var clonedRes = merge(target, src) - var notClonedRes = merge(target, src, {cloneWithTarget: true}) + var notClonedRes = merge(target, src, {mergeWithTarget: true}) t.assert(clonedRes !== target, 'result should be cloned') t.assert(notClonedRes === target, 'result should maintain target reference') t.end() }) -test('merge.all mutates target object when cloneWithTarget set to true', function(t) { +test('merge.all mutates target object when mergeWithTarget set to true', function(t) { var src = { key1: 'value1', key2: 'value2' } var target = { key3: 'value3'} var clonedRes = merge.all([target, src]) - var notClonedRes = merge.all([target, src], {cloneWithTarget: true}) + var notClonedRes = merge.all([target, src], {mergeWithTarget: true}) t.assert(clonedRes !== target, 'result should be cloned') t.assert(notClonedRes === target, 'result should maintain first array entry reference')