Repository URL to install this package:
|
Version:
1.2.18 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mergeDeep = mergeDeep;
exports.default = void 0;
var _removeNil = _interopRequireDefault(require("./removeNil"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
console.log('@DEPRECIATED - MERGEDEEP WILL BE REMOVED');
/**
* Deeply merges a given set of objects together.
*
* Objects to the right take priority.
*
* @NOTE @TODO this is not deepMerging,
* this is recursive value replacement & assignment,
* with a LOT of places for things to go wrong
*
*
* @example:
* /// here is the FIRST thing I tried
* /// (chooses longest string, doesn't have decision tree for data types)
* mergeDeep('canada', 'eh')
* //=> {0: 'c', 1: 'a', 2: 'n', 3: 'a', 4: 'd', 5: 'a'}
*
* @example:
*
*
* @TODO @MICHAEL
* this should be replaced
* with external libraries that specialize
* in covering all of the places that go wrong,
* ...and have tests, & so it is not maintained in-house
*
* @param {...Object} args - The objects to merge.
* @return {Object} - The merged object.
*/
function mergeDeep(...args) {
const filtered = (0, _removeNil.default)(args);
if (filtered.length < 1) {
return {};
}
if (filtered.length === 1) {
return args[0];
}
return filtered.reduce((acc, cur) => {
Object.keys(cur).forEach(key => {
if (typeof acc[key] === 'object' && typeof cur[key] === 'object') {
// @INVALID @NOTE this is not re-assign, not sure if it is an artifact
// eslint-disable-next-line no-param-reassign
acc[key] = mergeDeep(acc[key], cur[key]);
} else {
// eslint-disable-next-line no-param-reassign
acc[key] = cur[key];
}
});
return acc;
}, {});
}
var _default = mergeDeep;
exports.default = _default;