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 🙏

© 2024 – Pkg Stats / Ryan Hefner

code-complexity

v4.4.4

Published

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

Downloads

11,384

Readme

code-complexity

Measure the churn/complexity score. Higher scores reveal hotspots where refactorings should happen.

Build Status Coverage Status Style Status NPM Version

Quoting Michael Feathers (source here):

Often when we refactor, we look at local areas of code. If we take a wider view, using information from our version control systems, we can get a better sense of the effects of our refactoring efforts.

Note: code-complexity currently measures complexity using either:

  • lines of code count (all languages)
  • cyclomatic complexity (JavaScript/TypeScript)
  • halstead complexity (JavaScript/TypeScript)

Usage

$ npx code-complexity <path-to-git-directory or URL> [options]

Help

    Usage: code-complexity <target> [options]

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

    Options:
      -V, --version                         output the version number
      --filter <strings>                    list of globs (comma separated) to filter
      -cs, --complexity-strategy [strategy] choose the complexity strategy to analyze your codebase with (allowed values: sloc, cyclomatic, halstead).
      -f, --format [format]                 format results using table, json or csv
      -l, --limit [limit]                   limit the number of files to output
      -i, --since [since]                   limit analysis to commits more recent in age than date
      -u, --until [until]                   limit analysis to commits older in age than date
      -s, --sort [sort]                     sort results (allowed valued: score, churn, complexity or file)
      -d, --directories                     display values for directories instead of files
      -h, --help                            display help for command

    Examples:

    $ code-complexity .
    $ code-complexity https://github.com/simonrenoult/code-complexity
    $ code-complexity foo --limit 3
    $ code-complexity ../foo --sort score
    $ code-complexity /foo/bar --filter 'src/**,!src/front/**'
    $ code-complexity . --limit 10 --sort score
    $ code-complexity . --limit 10 --directories 
    $ code-complexity . --limit 10 --sort score -cs halstead
    $ code-complexity . --since=2021-06-01 --limit 100
    $ code-complexity . --since=2021-04-01 --until=2021-07-01

Output

$ npx code-complexity https://github.com/simonrenoult/code-complexity --sort=score --limit=3

┌──────────────────────────────┬────────────┬───────┬───────┐
│ file                         │ complexity │ churn │ score │
├──────────────────────────────┼────────────┼───────┼───────┤
│ src/cli.ts                   │ 103        │ 8     │ 824   │
├──────────────────────────────┼────────────┼───────┼───────┤
│ test/code-complexity.test.ts │ 107        │ 7     │ 749   │
├──────────────────────────────┼────────────┼───────┼───────┤
│ .idea/workspace.xml          │ 123        │ 6     │ 738   │
└──────────────────────────────┴────────────┴───────┴───────┘

Special thanks

A special thanks to a few contributors that helped me make code-complexity better.

  • Alexander Dormann (alexdo) for fixing the ENOBUFS (and apologies for stealing your code).
  • Scott Brooks (scottamplitude) for initiating the work on complexity strategies