UNPKG

@adaptabletools/adaptable-cjs

Version:

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

44 lines (43 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.diff = exports.deepClone = exports.isObjectEmpty = exports.setInPath = void 0; /** * Returns a new object with the property updated. * The property is identified by the path. * * @param obj Object * @param path path to the property * @param value new property value * @returns */ function setInPath(obj, path, value) { if (path.length === 1) { return { ...obj, [path[0]]: value, }; } return { ...obj, [path[0]]: setInPath(obj?.[path[0]] ?? {}, path.slice(1), value), }; } exports.setInPath = setInPath; function isObjectEmpty(obj) { return !obj || Object.keys(obj).length === 0; } exports.isObjectEmpty = isObjectEmpty; const deepClone = (obj) => { return JSON.parse(JSON.stringify(obj)); }; exports.deepClone = deepClone; const diff = (obj1, obj2) => { let changed = []; for (const key of Object.keys(obj1)) { if (obj1[key] !== obj2[key]) { changed.push(key); } } return changed; }; exports.diff = diff;