Repository
3 stars • 2 forks • 1 open issue
JAVASCRIPT + TYPESCRIPT METRICS
JTMetrics is a lightweight, extensible code metrics toolkit for JS/TS projects, with both a Node.js library and a Chrome extension that integrates directly into GitHub repository pages.
3 stars • 2 forks • 1 open issue
v1.1.0 (2026-04-01)
1 user • 686 KiB • English
Install the package and run calculateMetrics on a project folder.
npm install jtmetrics
import { calculateMetrics } from "jtmetrics";
import path from "node:path";
const results = await calculateMetrics({
codePath: path.resolve("./src"),
useDefaultMetrics: true,
customMetricsPath: "./my-custom-metrics",
metricsIgnoreFilePath: "./.metricsignore"
});
console.log(JSON.stringify(results, null, 2));
Main function: calculateMetrics(options)
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
codePath |
string | Yes | — | Absolute or resolvable path to the source folder to analyze. |
customMetricsPath |
string | No | — | Path to user-defined metric modules. |
useDefaultMetrics |
boolean | No | true | Include bundled built-in metrics. |
useBuiltinMetrics |
boolean | No | true | Legacy alias for useDefaultMetrics (takes precedence when provided). |
metricsIgnoreFilePath |
string | No | — | Path to a .metricsignore file. |
JTMetrics ships with a broad built-in set covering structure, size, and coupling analysis.
| ID | Name | Purpose |
|---|---|---|
files | Files | Lists all source files in scope. |
lines-per-file | Lines Per File | Counts total/non-empty lines per file. |
functions-per-file | Functions Per File | Counts function declarations per file. |
parameter-count | Parameter Count | Tracks parameter counts for named functions. |
function-length | Function Length | Computes line span of each function. |
function-coupling | Function Coupling | Computes fan-in/fan-out at function level. |
classes-per-file | Classes Per File | Maps classes and members by file. |
class-coupling | Class Coupling | Computes fan-in/fan-out for class methods. |
class-dependency-summary | Class Dependency Summary | Aggregates class dependency totals. |
function-dependency-summary | Function Dependency Summary | Aggregates function dependency totals. |
file-coupling | File Coupling | Analyzes imports/require relationships. |
import-instability | Import Instability | Computes instability from afferent/efferent coupling. |
dependency-centrality | Dependency Centrality | Calculates in/out/total centrality. |
instance-mapper | Instance Mapper | Maps object instances to classes for call resolution. |
The extension adds JTMetrics analysis directly inside GitHub repository pages and allows exporting results as JSON.
storagehttps://github.com/*, https://api.github.com/*
For automated analysis in CI, run calculateMetrics in a workflow and write a JSON artifact or commit into a metrics branch.
env:
CODE_PATH: src
run: |
node --input-type=module -e "
import path from 'node:path';
import fs from 'node:fs/promises';
import { calculateMetrics } from 'jtmetrics';
const absoluteCodePath = path.resolve(process.env.GITHUB_WORKSPACE, process.env.CODE_PATH);
const results = await calculateMetrics({ codePath: absoluteCodePath });
await fs.mkdir('jtmetrics-output', { recursive: true });
await fs.writeFile('jtmetrics-output/metrics.json', JSON.stringify(results, null, 2));
"
No. The npm package runs directly in Node.js. The extension is an optional GitHub UX layer.
Yes. Provide a custom metrics folder with modules exporting metric state, visitors, and optional post-processing.
Yes. Save results as JSON files, upload as CI artifacts, or commit to a dedicated branch (for example, metrics-data).