UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

33 lines (28 loc) 845 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var object_equal = require('./equal.js'); 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 (!object_equal.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; } exports.compareTwoObj = compareTwoObj;