UNPKG

code-complexity

Version:

Measure the churn/complexity score. Higher values mean hotspots where refactorings should happen.

51 lines (50 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Table = require("cli-table3"); const utils_1 = require("../utils"); const internal = { debug: (0, utils_1.buildDebugger)("output") }; exports.default = { render: (...args) => (0, utils_1.withDuration)(render, args, internal.debug), }; function render(statistics, options) { let stdout; switch (options.format) { case "table": stdout = toTable(statistics); break; case "json": stdout = toJson(statistics); break; case "csv": stdout = toCSV(statistics); break; default: stdout = toTable(statistics); } console.log(stdout); } function toJson(statistics) { return JSON.stringify(statistics); } function toTable(statistics) { const table = new Table({ head: ["file", "complexity", "churn", "score"], }); statistics.forEach((statistics) => { table.push([ statistics.path, statistics.complexity, statistics.churn, statistics.score, ]); }); return table.toString(); } function toCSV(statistics) { let csv = "file,complexity,churn,score\n"; statistics.forEach((stat) => { csv += [stat.path, stat.complexity, stat.churn, stat.score].join(",") + "\n"; }); return csv; }