UNPKG

@beincom/dto

Version:

Share dto for all projects of Beincom

24 lines (23 loc) 961 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetPropsChanged = void 0; const lodash_1 = require("lodash"); function GetPropsChanged(old = {}, current = {}) { const changes = {}; const allKeys = (0, lodash_1.union)((0, lodash_1.keys)(old), (0, lodash_1.keys)(current)); allKeys.forEach((key) => { const isOldUndefined = !old || old[key] === undefined; const isCurrentUndefined = !current || current[key] === undefined; if (isOldUndefined && !isCurrentUndefined) { changes[key] = { old: null, new: current[key] }; } else if (!isOldUndefined && isCurrentUndefined) { changes[key] = { old: old[key], new: null }; } else if (JSON.stringify(old[key]) !== JSON.stringify(current[key])) { changes[key] = { old: old[key], new: current[key] }; } }); return changes; } exports.GetPropsChanged = GetPropsChanged;