Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/diff.js

31 lines
4.3 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
function getFullPropertyPath(property, parentProperty) {
if (parentProperty)
return `${parentProperty}.${property}`;
return property;
}
function diff(source, modified, result, parentProperty = '') {
for (const property in source) {
const fullPropertyPath = getFullPropertyPath(property, parentProperty);
if (!modified.hasOwnProperty(property))
continue;
const sourceValue = source[property];
const modifiedValue = modified[property];
if (sourceValue !== modifiedValue) {
if ((0, lodash_1.isObjectLike)(sourceValue) && (0, lodash_1.isObjectLike)(modifiedValue))
diff(sourceValue, modifiedValue, result, fullPropertyPath);
else
(0, lodash_1.set)(result, fullPropertyPath, modifiedValue);
}
}
}
exports.default = (source, modified) => {
const result = {};
if ((0, lodash_1.isObjectLike)(source) && (0, lodash_1.isObjectLike)(modified))
diff(source, modified, result);
return result;
};
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGlmZi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9kaWZmLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsbUNBQTJDO0FBRzNDLFNBQVMsbUJBQW1CLENBQUUsUUFBZ0IsRUFBRSxjQUFzQjtJQUNsRSxJQUFJLGNBQWM7UUFDZCxPQUFPLEdBQUcsY0FBYyxJQUFJLFFBQVEsRUFBRSxDQUFDO0lBRTNDLE9BQU8sUUFBUSxDQUFDO0FBQ3BCLENBQUM7QUFFRCxTQUFTLElBQUksQ0FBRSxNQUEwQixFQUFFLFFBQTRCLEVBQUUsTUFBMEIsRUFBRSxjQUFjLEdBQUcsRUFBRTtJQUNwSCxLQUFLLE1BQU0sUUFBUSxJQUFJLE1BQU0sRUFBRTtRQUMzQixNQUFNLGdCQUFnQixHQUFHLG1CQUFtQixDQUFDL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