UNPKG

assertthat

Version:
31 lines (30 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dispelMap = void 0; const dispel_1 = require("./dispel"); const typedescriptor_1 = require("typedescriptor"); const uuid_1 = require("uuid"); const Recursion_1 = require("../types/Recursion"); const dispelMap = function (value, path = '/', ancestors = []) { for (const ancestor of ancestors) { if (value === ancestor.reference) { return (0, Recursion_1.recursion)({ recursionPath: ancestor.path }); } } const newAncestors = [ ...ancestors, { reference: value, path } ]; const dispelledMap = new Map(); for (const [key, subValue] of value.entries()) { const newPath = (0, typedescriptor_1.isScalar)(key) ? `${path}map-${String(key)}/` : `${path}map-${(0, uuid_1.v4)()}/`; dispelledMap.set(key, (0, dispel_1.dispel)(subValue, newPath, newAncestors)); } return dispelledMap; }; exports.dispelMap = dispelMap;