UNPKG

assertthat

Version:
68 lines (67 loc) 3.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prettyPrint = void 0; const errors_1 = require("../../errors"); const Recursion_1 = require("../../types/Recursion"); const defekt_1 = require("defekt"); const prettyPrintArray_1 = require("../forArrays/prettyPrintArray"); const prettyPrintBoolean_1 = require("../forBooleans/prettyPrintBoolean"); const prettyPrintError_1 = require("../forErrors/prettyPrintError"); const prettyPrintFunction_1 = require("../forFunctions/prettyPrintFunction"); const prettyPrintMap_1 = require("../forMaps/prettyPrintMap"); const prettyPrintNull_1 = require("../forNull/prettyPrintNull"); const prettyPrintNumber_1 = require("../forNumbers/prettyPrintNumber"); const prettyPrintObject_1 = require("../forObjects/prettyPrintObject"); const prettyPrintRecursion_1 = require("../forRecursions/prettyPrintRecursion"); const prettyPrintResult_1 = require("../forResults/prettyPrintResult"); const prettyPrintSet_1 = require("../forSets/prettyPrintSet"); const prettyPrintString_1 = require("../forStrings/prettyPrintString"); const prettyPrintSymbol_1 = require("../forSymbols/prettyPrintSymbol"); const prettyPrintUndefined_1 = require("../forUndefined/prettyPrintUndefined"); const typedescriptor_1 = require("typedescriptor"); const prettyPrint = function (value, depth = 0) { if ((0, Recursion_1.isRecursion)(value)) { return (0, prettyPrintRecursion_1.prettyPrintRecursion)(value); } if ((0, typedescriptor_1.isError)(value)) { return (0, prettyPrintError_1.prettyPrintError)(value, depth); } if ((0, typedescriptor_1.isSet)(value)) { return (0, prettyPrintSet_1.prettyPrintSet)(value, depth); } if ((0, typedescriptor_1.isMap)(value)) { return (0, prettyPrintMap_1.prettyPrintMap)(value, depth); } if ((0, typedescriptor_1.isArray)(value)) { return (0, prettyPrintArray_1.prettyPrintArray)(value, depth); } if ((0, defekt_1.isResult)(value)) { return (0, prettyPrintResult_1.prettyPrintResult)(value, depth); } if ((0, typedescriptor_1.isNumber)(value)) { return (0, prettyPrintNumber_1.prettyPrintNumber)(value); } if ((0, typedescriptor_1.isString)(value)) { return (0, prettyPrintString_1.prettyPrintString)(value); } if ((0, typedescriptor_1.isBoolean)(value)) { return (0, prettyPrintBoolean_1.prettyPrintBoolean)(value); } if ((0, typedescriptor_1.isSymbol)(value)) { return (0, prettyPrintSymbol_1.prettyPrintSymbol)(value); } if ((0, typedescriptor_1.isFunction)(value)) { return (0, prettyPrintFunction_1.prettyPrintFunction)(value); } if ((0, typedescriptor_1.isObject)(value)) { return (0, prettyPrintObject_1.prettyPrintObject)(value, depth); } if ((0, typedescriptor_1.isUndefined)(value)) { return (0, prettyPrintUndefined_1.prettyPrintUndefined)(value); } if ((0, typedescriptor_1.isNull)(value)) { return (0, prettyPrintNull_1.prettyPrintNull)(value); } throw new errors_1.InvalidOperation('Could not pretty print a value with unknown type.'); }; exports.prettyPrint = prettyPrint;