t-comm
Version:
专业、稳定、纯粹的工具库
29 lines (26 loc) • 762 B
JavaScript
import { isObjectEqual as _isObjectEqual } from './equal.mjs';
function compareTwoObj() {
var originObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var newObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var res = {
ADDED: [],
UPDATED: [],
DELETED: [],
originObj: originObj,
newObj: newObj
};
Object.keys(originObj).map(function (key) {
if (newObj[key] === undefined) {
res.DELETED.push(key);
} else if (!_isObjectEqual(newObj[key], originObj[key])) {
res.UPDATED.push(key);
}
});
Object.keys(newObj).map(function (key) {
if (originObj[key] === undefined) {
res.ADDED.push(key);
}
});
return res;
}
export { compareTwoObj };