@snyk/dep-graph
Version:
Snyk dependency graph library
26 lines • 867 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCycle = getCycle;
exports.partitionCycles = partitionCycles;
function getCycle(ancestors, nodeId) {
if (!ancestors.includes(nodeId)) {
return null;
}
// first item is where the cycle starts and ends.
return ancestors.slice(ancestors.indexOf(nodeId));
}
function partitionCycles(nodeId, allCyclesTheNodeIsPartOf) {
const cyclesStartWithThisNode = [];
const cyclesWithThisNode = [];
for (const cycle of allCyclesTheNodeIsPartOf) {
const nodeStartsCycle = cycle[0] === nodeId;
if (nodeStartsCycle) {
cyclesStartWithThisNode.push(cycle);
}
else {
cyclesWithThisNode.push(cycle);
}
}
return { cyclesStartWithThisNode, cyclesWithThisNode };
}
//# sourceMappingURL=cycles.js.map