From 4156feca2767386fd1152bf715551602e7d30014 Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 14 May 2018 11:27:34 -0700 Subject: [PATCH] remove deepMerge util --- src/lib/utils.js | 28 ---------------------------- test/unit/specs/utils.js | 39 --------------------------------------- 2 files changed, 67 deletions(-) diff --git a/src/lib/utils.js b/src/lib/utils.js index 923049c20..520d0a7c2 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -11,34 +11,6 @@ var utils = {}; utils.inherits = nodeUtils.inherits; -/** - * Recursively merge two objects, walking into each object and concating arrays. If both to and from have a value at a - * key, but the values' types don't match to's value is left unmodified. Only Array and Object values are merged - that - * it to say values with a typeof "object" - * - * @param {Object} to - Object to merge into (no cloning, the original object - * is modified) - * @param {Object} from - Object to pull changed from - * @return {Object} - returns the modified to value - */ -utils.deepMerge = function (to, from) { - _.each(from, function (fromVal, key) { - switch (typeof to[key]) { - case 'undefined': - to[key] = from[key]; - break; - case 'object': - if (_.isArray(to[key]) && _.isArray(from[key])) { - to[key] = to[key].concat(from[key]); - } - else if (_.isPlainObject(to[key]) && _.isPlainObject(from[key])) { - utils.deepMerge(to[key], from[key]); - } - } - }); - return to; -}; - /** * Test if a value is an array and its contents are string type * diff --git a/test/unit/specs/utils.js b/test/unit/specs/utils.js index 7d58e4873..27ad16cff 100644 --- a/test/unit/specs/utils.js +++ b/test/unit/specs/utils.js @@ -193,45 +193,6 @@ describe('Utils', function () { }); - - describe('#deepMerge', function () { - - it('returns the same object that was passed', function () { - var obj = { - foo: 'bar' - }; - expect(utils.deepMerge(obj, { bar: 'baz' })).to.eql(obj); - }); - - it('concats arrays', function () { - var obj = { - foo: ['bax', 'boz'] - }; - utils.deepMerge(obj, { foo: ['boop'] }); - expect(obj.foo).to.have.length(3); - }); - - it('wont merge values of different types', function () { - var obj = { - foo: ['stop', 'foo', 'stahp'] - }; - utils.deepMerge(obj, { foo: 'string' }); - expect(obj.foo).to.have.length(3); - }); - - it('works recursively', function () { - var obj = { - foo: 'bar', - bax: { - foo: ['bax', 'boz'] - } - }; - utils.deepMerge(obj, { bax: { foo: ['poo'] } }); - expect(obj.bax.foo).to.have.length(3); - }); - - }); - describe('#createArray', function () { it('accepts an array of things and simply returns a copy of it', function () { var inp = [{ a: 1 }, 'pizza'];