code-complexity
Version:
Measure the churn/complexity score. Higher values mean hotspots where refactorings should happen.
30 lines (29 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../utils");
const complexity_1 = require("./complexity");
const internal = { debug: (0, utils_1.buildDebugger)("complexity") };
class Complexities {
complexityByPath;
static async computeFor(paths, options) {
internal.debug(`${paths.length} files to compute complexity on`);
const complexities = await Promise.all(paths.map(async (p) => await complexity_1.default.compute(p, options)));
return new Complexities(complexities);
}
getByPath(path) {
const complexity = this.complexityByPath.get(path);
if (!complexity)
throw new Error("Complexity not found for path: " + path);
return complexity;
}
constructor(complexities) {
this.complexityByPath = this.computeComplexitiesPerPath(complexities);
}
computeComplexitiesPerPath(complexities) {
return complexities.reduce((map, complexity) => {
map.set(complexity.path, complexity);
return map;
}, new Map());
}
}
exports.default = Complexities;