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 🙏

© 2025 – Pkg Stats / Ryan Hefner

codeinsights

v1.0.1

Published

Concise code quality analysis CLI tool

Downloads

16

Readme

Code Analysis Tools

A suite of tools for analyzing and improving codebase quality.

Features

  • Import Analysis: Find unused imports in JavaScript and TypeScript files
  • Codebase Analysis: Analyze code structure, documentation quality, and identify redundant patterns
  • Complexity Analysis: Identify complex code and suggest refactoring opportunities

Directory Structure

scripts/
  ├── config/              # Shared configuration
  │   └── analysis_config.js   # Configuration management
  │
  ├── utils/               # Shared utilities
  │   ├── file_utils.js        # File finding utilities
  │   ├── code_analysis.js     # Code pattern analysis utilities
  │   ├── code_preprocessor.js # Code preprocessing utilities
  │   ├── report_generator.js  # Report generation utilities
  │   └── index.js             # Entry point for all utilities
  │
  ├── analyze_all.js       # Main entry point for running all analyses
  ├── analyze_codebase.js  # Codebase structure analysis
  ├── check_imports.js     # Import usage analysis
  └── refactor_complexity.js # Code complexity analysis and refactoring suggestions

Usage

Installation

npm install

Running Analysis

Run comprehensive analysis:

npm run analyze

Or run individual checks:

# Check for unused imports
npm run check-imports

# Analyze codebase structure
npm run analyze-codebase

# Analyze code complexity
npm run analyze-complexity

Command Line Options

All scripts support the following options:

  • --exclude-dirs: Comma-separated list of directories to exclude (default: node_modules,.git)
  • --extensions: Comma-separated list of file extensions to analyze (default: .js,.ts,.jsx,.tsx)
  • --reports-dir: Directory to save reports (default: reports)

Complexity analysis also supports:

  • --complexity-threshold: Cyclomatic complexity threshold (default: 10)
  • --max-function-length: Maximum function length in statements (default: 30)

Reports

All reports are saved to the reports directory as JSON files:

  • unused_imports_report.json: List of unused imports
  • codebase_analysis_report.json: Codebase structure analysis
  • refactoring_suggestions.json: Complexity analysis and refactoring suggestions

Architecture

The codebase follows these architectural principles:

  1. Modularity: All functionality is split into small, focused modules
  2. DRY (Don't Repeat Yourself): Common functionality is extracted into shared utilities
  3. Configuration Management: Centralized configuration with sensible defaults
  4. Standardized Reporting: Consistent report generation and formatting

CodeStats

A concise code analysis CLI tool that helps you improve your codebase by analyzing:

  • Code Complexity: Find complex functions and code patterns
  • Documentation: Check JSDoc completeness
  • Redundant Patterns: Identify duplicated code
  • Unused Imports: Find unused imports in your code

Installation

# Global installation 
npm install -g codestats

# Or run with npx
npx codestats

Usage

# Analyze the current project directory
codestats

# Analyze a specific directory
codestats -d ./my-project

# Specify extensions to analyze
codestats -e .js,.ts,.jsx,.tsx

# Exclude specific directories
codestats -x node_modules,.git,dist,build

# Quiet mode (minimal output)
codestats -q

# Help
codestats --help

Features

Comprehensive CLI Output

  • Color-coded summary for quick assessment
  • Detailed analysis showing specific issues
  • Actionable recommendations based on findings
  • No external reports - everything happens in your terminal
  • Fast analysis with minimal dependencies

Comprehensive Analysis

  • Function complexity scoring
  • Documentation completeness checking
  • Redundant code pattern detection
  • Unused import identification

Example Output

═════════════════════════════════════
📊 CODEBASE ANALYSIS SUMMARY
═════════════════════════════════════
Files Analyzed: 42
Average Complexity: 5.3
Complex Functions: 8/127
Documentation: 62.5%
Undocumented Functions: 24
Redundant Patterns: 6
Potential LOC Savings: 83
Unused Imports: 12
═════════════════════════════════════

🔥 MOST COMPLEX FUNCTIONS:
1. processData in main.js:127 [18]
2. renderComponent in component.js:48 [16]
3. calculateTotals in utils.js:92 [14]
4. validateInput in validators.js:35 [13]
5. parseConfig in config.js:65 [12]

📁 MOST COMPLEX FILES:
1. main.js - 12.5 avg complexity (8 functions)
2. validators.js - 9.3 avg complexity (5 functions)
3. utils.js - 7.8 avg complexity (12 functions)

📝 UNDOCUMENTED FUNCTIONS:
1. formatData in formatter.js:25
2. validateInput in validator.js:42
3. parseConfig in config.js:18
  ... and 21 more

🔄 REDUNDANT CODE PATTERNS:
1. utility pattern appears 5 times (41 lines savable)
   Snippet: function formatDate(date) { return date.toISOString().split('T')[0]; }
   Appears in:
   - utils.js:45
   - helpers.js:23
   - formatter.js:12

2. operation pattern appears 3 times (24 lines savable)
   Snippet: data.filter(item => item.active).map(item => item.value).reduce((a, b) => a + b, 0)
   Appears in:
   - main.js:89
   - reports.js:56
   - dashboard.js:102

📦 UNUSED IMPORTS:
main.js:
  - fs (line 3)
  - path (line 4)
utils.js:
  - moment (line 2)
  ... and 9 more

💡 RECOMMENDATIONS:
• Refactor complex functions to improve maintainability
• Improve documentation coverage with JSDoc comments
• Extract repeated patterns into shared utilities
• Remove unused imports to clean up code

Project Structure

bin/
  └── index.js           # CLI entry point
lib/
  ├── analyzer.js        # Main analysis orchestration
  ├── core.js            # Core analysis functions
  └── utils/             # Utility functions
      ├── complexity.js  # Complexity calculation
      └── parser.js      # Code parsing utilities

License

MIT