assertthat
Version:
assertthat provides fluent TDD.
28 lines (27 loc) • 857 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dispelObject = void 0;
const dispel_1 = require("./dispel");
const Recursion_1 = require("../types/Recursion");
const dispelObject = 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 dispelledObject = {};
for (const [key, subValue] of Object.entries(value)) {
dispelledObject[key] = (0, dispel_1.dispel)(subValue, `${path}${key}/`, newAncestors);
}
return dispelledObject;
};
exports.dispelObject = dispelObject;