UNPKG

assertthat

Version:
32 lines (31 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dispelError = void 0; const dispel_1 = require("./dispel"); const LessShittyError_1 = require("../types/LessShittyError"); const Recursion_1 = require("../types/Recursion"); const dispelError = function (value, path = '/', ancestors = []) { for (const ancestor of ancestors) { if (value === ancestor.reference) { return (0, Recursion_1.recursion)({ recursionPath: ancestor.path }); } } const lessShittyError = (0, LessShittyError_1.makeErrorLessShitty)({ error: value }); const newAncestors = [ ...ancestors, { reference: value, path } ]; const dispelledError = Object.create(value); for (const [key, property] of Object.entries(lessShittyError)) { dispelledError[key] = (0, dispel_1.dispel)(property, `${path}${key}/`, newAncestors); } return dispelledError; }; exports.dispelError = dispelError;