UNPKG

assertthat

Version:
40 lines (39 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prettyPrintMapDiff = 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 prettyPrintMapDiff = function (diff, depth = 0) { const content = []; for (const [key, value] of diff.equal.entries()) { content.push((0, prepareSimple_1.prepareSimple)(`${(0, prettyPrint_1.prettyPrint)(key, Number.POSITIVE_INFINITY)}: ${(0, prettyPrint_1.prettyPrint)(value, depth + 1)}`, depth)); } for (const [key, value] of diff.changes.entries()) { content.push((0, prepareChange_1.prepareChange)(`${(0, prettyPrint_1.prettyPrint)(key, Number.POSITIVE_INFINITY)}: ${(0, prettyPrintDiff_1.prettyPrintDiff)(value, depth + 1)}`, depth)); } for (const [key, value] of diff.omissions.entries()) { content.push((0, prepareOmission_1.prepareOmission)(`${(0, prettyPrint_1.prettyPrint)(key, Number.POSITIVE_INFINITY)}: ${(0, prettyPrint_1.prettyPrint)(value, depth + 1)}`, depth)); } for (const [key, value] of diff.additions.entries()) { content.push((0, prepareAddition_1.prepareAddition)(`${(0, prettyPrint_1.prettyPrint)(key, Number.POSITIVE_INFINITY)}: ${(0, prettyPrint_1.prettyPrint)(value, depth + 1)}`, depth)); } if (content.length === 0) { return 'Map({})'; } if (depth >= maximumFormattingDepth_1.maximumFormattingDepth) { return (0, formatNestedArray_1.formatNestedArray) `Map({ ${content} })`; } return (0, propagateDiffSymbols_1.propagateDiffSymbols)((0, formatNestedArray_1.formatNestedArray) ` Map({ ${content} }) `); }; exports.prettyPrintMapDiff = prettyPrintMapDiff;