npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@andy-toolforge/coding-support

v1.0.2

Published

Toolforge domain: Code analysis tools — line counting, dead code detection, dependency graphs, complexity reports

Downloads

639

Readme

@andy-toolforge/coding-support

npm License

Static code analysis: line counts, dead code, dependency graphs, complexity. Thuộc hệ sinh thái toolforge.

Package này giúp bạn:

  • Đếm dòng code (total, code, comment, blank) theo glob patterns
  • Tìm code chết — exports không được require từ entry points
  • Sinh dependency graph của JS/TS project
  • Báo cáo complexity: số functions, decisions, nesting depth, max line length

Installation

npm install @andy-toolforge/coding-support

Yêu cầu @andy-toolforge/core (tự động cài kèm).

API Reference

const { CodebaseAnalyzer } = require('@andy-toolforge/coding-support');

CodebaseAnalyzer

Constructor: new CodebaseAnalyzer({ rootDir?, logger? })

Mặc định rootDirprocess.cwd().


countLines(patterns)

Đếm dòng code cho files matching glob patterns.

| Param | Type | Mô tả | |-------|------|-------| | patterns | string | string[] | Glob pattern(s) (vd: 'lib/**/*.js') |

Return:

{
  files: 10,
  totalLines: 500,
  codeLines: 350,
  commentLines: 80,
  blankLines: 70,
  byFile: [
    { file: 'lib/index.js', totalLines: 50, codeLines: 35, commentLines: 10, blankLines: 5 },
    // ...
  ]
}
const { CodebaseAnalyzer } = require('@andy-toolforge/coding-support');

const analyzer = new CodebaseAnalyzer();
const counts = await analyzer.countLines('lib/**/*.js');
console.log(`📊 ${counts.files} files, ${counts.codeLines} LOC`);

findDeadCode(entryPoints)

Tìm exports không được require từ entry points.

| Param | Type | Mô tả | |-------|------|-------| | entryPoints | string | string[] | Entry file path(s) |

Return:

[
  { file: 'src/utils/old.js', exports: ['helper1', 'helper2'], reason: 'File is not required' },
  // ...
]
const dead = await analyzer.findDeadCode('src/index.js');
if (dead.length > 0) {
    console.log(`🗑️  ${dead.length} potentially dead files:`);
    dead.forEach(d => console.log(`  - ${d.file}: ${d.exports.join(', ')}`));
}

Hoạt động: quét tất cả require() trong project → build graph → so sánh với exports. Hỗ trợ cả module.exports.X =module.exports = { X }.


generateDependencyGraph()

Sinh dependency graph của tất cả JS files.

Return:

{
  nodes: [{ id: 0, path: 'src/index.js', name: 'index.js' }, ...],
  edges: [{ from: 0, to: 1, source: './utils' }, ...]
}
const graph = await analyzer.generateDependencyGraph();
console.log(`${graph.nodes.length} files, ${graph.edges.length} dependencies`);

Dùng được với d3-force hoặc cytoscape để visualize.


complexityReport(files)

Báo cáo complexity metrics cho từng file.

| Param | Type | Mô tả | |-------|------|-------| | files | string | string[] | File paths |

Return:

[
  {
    file: 'src/index.js',
    totalLines: 100,
    codeLines: 70,
    commentLines: 15,
    blankLines: 15,
    functions: 5,
    decisions: 12,
    maxNestingDepth: 3,
    maxLineLength: 80
  }
]
const report = await analyzer.complexityReport(['src/index.js', 'src/utils.js']);
report.forEach(r => {
    const flag = r.maxNestingDepth > 4 ? '⚠️' : '✅';
    console.log(`${flag} ${r.file}: ${r.functions} funcs, depth ${r.maxNestingDepth}`);
});

Tutorial: Codebase Health Check

const analyzer = new CodebaseAnalyzer();

async function healthCheck() {
    // Bước 1: Size
    const counts = await analyzer.countLines(['lib/**/*.js', 'src/**/*.js']);
    console.log(`📊 Codebase: ${counts.codeLines} LOC in ${counts.files} files`);

    // Bước 2: Dead code
    const dead = await analyzer.findDeadCode('src/index.js');
    if (dead.length > 0) console.log(`🗑️  ${dead.length} dead file(s)`);

    // Bước 3: Complexity hotspots
    const allFiles = counts.byFile.map(f => f.file);
    const complexity = await analyzer.complexityReport(allFiles);
    const hotspots = complexity.filter(c => c.maxNestingDepth > 4);
    if (hotspots.length > 0) console.log(`⚠️  ${hotspots.length} complex file(s)`);

    return { counts, dead, hotspots };
}

Related