UNPKG

react-tesna-utils

Version:

A versatile utility library featuring optimized functions for data manipulation, clipboard handling, text truncation, comparison, validation, and more. Designed for modern JavaScript and TypeScript projects with efficient and reusable solutions.

36 lines (35 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deepCompareAndRemove = void 0; function deepCompareAndRemove(obj1, obj2) { if (!obj2) return obj1; const result = Array.isArray(obj1) ? [...obj1] : Object.assign({}, obj1); for (const key in result) { if (key in obj2) { if (typeof result[key] === 'object' && typeof obj2[key] === 'object' && result[key] !== null && obj2[key] !== null) { const nestedResult = deepCompareAndRemove(result[key], obj2[key]); if (Array.isArray(nestedResult) && nestedResult.length === 0) { delete result[key]; } else if (Object.keys(nestedResult).length === 0) { delete result[key]; } else { result[key] = nestedResult; } } else if (result[key] === obj2[key]) { delete result[key]; } } } if (Array.isArray(result)) { return result.filter((item) => !(typeof item === 'object' && Object.keys(item).length === 0)); } return result; } exports.deepCompareAndRemove = deepCompareAndRemove;