JAVASCRIPT + TYPESCRIPT METRICS

JTMetrics Documentation Hub

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.

npm: 1.1.0 Node: >= 18 License: MIT Extension: 0.1.2

Repository

3 stars • 2 forks • 1 open issue

Latest npm release

v1.1.0 (2026-04-01)

Chrome extension

1 user • 686 KiB • English

Quick Start

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));

API Reference

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.

Built-in Metrics

JTMetrics ships with a broad built-in set covering structure, size, and coupling analysis.

ID Name Purpose
filesFilesLists all source files in scope.
lines-per-fileLines Per FileCounts total/non-empty lines per file.
functions-per-fileFunctions Per FileCounts function declarations per file.
parameter-countParameter CountTracks parameter counts for named functions.
function-lengthFunction LengthComputes line span of each function.
function-couplingFunction CouplingComputes fan-in/fan-out at function level.
classes-per-fileClasses Per FileMaps classes and members by file.
class-couplingClass CouplingComputes fan-in/fan-out for class methods.
class-dependency-summaryClass Dependency SummaryAggregates class dependency totals.
function-dependency-summaryFunction Dependency SummaryAggregates function dependency totals.
file-couplingFile CouplingAnalyzes imports/require relationships.
import-instabilityImport InstabilityComputes instability from afferent/efferent coupling.
dependency-centralityDependency CentralityCalculates in/out/total centrality.
instance-mapperInstance MapperMaps object instances to classes for call resolution.

Chrome Extension: JTMetrics for GitHub

The extension adds JTMetrics analysis directly inside GitHub repository pages and allows exporting results as JSON.

Extension facts

  • Version: 0.1.2
  • Store category: Developer Tools
  • Users: 1
  • Size: 686 KiB
  • Last store update: 2026-03-30

Manifest highlights

  • Manifest version: 3
  • Permissions: storage
  • Host access: https://github.com/*, https://api.github.com/*
  • Content script: injects on GitHub pages
  • Options page included
JTMetrics extension screenshot JTMetrics extension screenshot

GitHub Actions Integration Pattern

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));
  "

Timeline

  1. 2025-11-09: npm package published (v1.0.0)
  2. 2026-03-24: Chrome extension listing active in Chrome Web Store
  3. 2026-03-30: Extension version 0.1.2 updated
  4. 2026-04-01: npm package updated to v1.1.0

FAQ

Do I need the Chrome extension to use JTMetrics?

No. The npm package runs directly in Node.js. The extension is an optional GitHub UX layer.

Can I add my own metrics?

Yes. Provide a custom metrics folder with modules exporting metric state, visitors, and optional post-processing.

Can results be persisted?

Yes. Save results as JSON files, upload as CI artifacts, or commit to a dedicated branch (for example, metrics-data).

Resources