UNPKG

assertthat

Version:
40 lines (39 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prettyPrintObjectDiff = void 0; const formatNestedArray_1 = require("../utils/formatNestedArray"); const maximumFormattingDepth_1 = require("../../constants/maximumFormattingDepth"); const prepareAddition_1 = require("../utils/prepareAddition"); const prepareChange_1 = require("../utils/prepareChange"); const prepareOmission_1 = require("../utils/prepareOmission"); const prepareSimple_1 = require("../utils/prepareSimple"); const prettyPrint_1 = require("../typeAware/prettyPrint"); const prettyPrintDiff_1 = require("../typeAware/prettyPrintDiff"); const propagateDiffSymbols_1 = require("../utils/propagateDiffSymbols"); const prettyPrintObjectDiff = function (diff, depth = 0) { const content = []; for (const [key, value] of Object.entries(diff.equal)) { content.push((0, prepareSimple_1.prepareSimple)(`${key}: ${(0, prettyPrint_1.prettyPrint)(value, depth + 1)}`, depth)); } for (const [key, value] of Object.entries(diff.changes)) { content.push((0, prepareChange_1.prepareChange)(`${key}: ${(0, prettyPrintDiff_1.prettyPrintDiff)(value, depth + 1)}`, depth)); } for (const [key, value] of Object.entries(diff.omissions)) { content.push((0, prepareOmission_1.prepareOmission)(`${key}: ${(0, prettyPrint_1.prettyPrint)(value, depth + 1)}`, depth)); } for (const [key, value] of Object.entries(diff.additions)) { content.push((0, prepareAddition_1.prepareAddition)(`${key}: ${(0, prettyPrint_1.prettyPrint)(value, depth + 1)}`, depth)); } if (content.length === 0) { return '{}'; } if (depth >= maximumFormattingDepth_1.maximumFormattingDepth) { return (0, formatNestedArray_1.formatNestedArray) `{ ${content} }`; } return (0, propagateDiffSymbols_1.propagateDiffSymbols)((0, formatNestedArray_1.formatNestedArray) ` { ${content} } `); }; exports.prettyPrintObjectDiff = prettyPrintObjectDiff;