UNPKG

@adaptabletools/adaptable-cjs

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

45 lines (44 loc) 1.48 kB
"use strict"; /** * Recursively merges own enumerable string keyed properties of source objects into * the destination object. Source properties that resolve to undefined are skipped if * a destination value exists. Array and plain object properties are merged recursively. * Other objects and value types are overridden by assignment. * Drop-in replacement for lodash/merge. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = merge; const tslib_1 = require("tslib"); const isPlainObject_1 = tslib_1.__importDefault(require("./isPlainObject")); function baseMerge(target, source) { if (source == null) { return target; } const keys = Object.keys(source); for (const key of keys) { const srcValue = source[key]; const tgtValue = target[key]; if (Array.isArray(srcValue)) { if (!Array.isArray(tgtValue)) { target[key] = []; } baseMerge(target[key], srcValue); } else if ((0, isPlainObject_1.default)(srcValue)) { if (!(0, isPlainObject_1.default)(tgtValue)) { target[key] = {}; } baseMerge(target[key], srcValue); } else if (srcValue !== undefined) { target[key] = srcValue; } } return target; } function merge(target, ...sources) { for (const source of sources) { baseMerge(target, source); } return target; }