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

@amir-bagjani/loc-counter

v0.1.0

Published

CLI to count lines of code in frontend projects

Readme

loc-counter

npm version npm downloads

A simple CLI tool written in TypeScript that counts lines of code in your project.
Designed for frontend projects, it ignores non-code files (Markdown, images, lockfiles, etc.) and provides per-extension breakdowns.


✨ Features

  • Count total lines, non-empty lines, and comment-only lines
  • Per-extension statistics
  • Top N largest files by line count
  • JSON or text output
  • Optional file count mode
  • Ignores common non-code files (.md, .json, images, etc.)

📦 Installation

# install globally
npm install -g @amir-bagjani/loc-counter

# or use with npx (no install required)
npx @amir-bagjani/loc-counter ./my-project

🚀 Usage

loc-counter <path> [options]

Examples

# Count lines in current folder
loc-counter .

# Show top 5 largest files
loc-counter ./src --top 5

# Output results in JSON format
loc-counter ./app --format json

⚙️ Options

| Flag | Description | Default | |-------------------|-----------------------------------------------------------------------------|---------| | --top <N> | Show the N largest files by line count | 10 | | --format <type> | Output format: text or json | text |

📊 Example Output

Text format

LOC Counter report
Target: ./src
Files counted: 124
Total lines: 13842
Non-empty lines: 11239
Comment-only lines (heuristic): 2123

Per-extension breakdown:
  ts     files:   34  lines:    7200  non-empty:   5800  comments:   900
  js     files:   20  lines:    3000  non-empty:   2500  comments:   200

Top largest files:
   1024 lines  src/App.tsx
    900 lines  src/components/BigComponent.tsx

JSON format

{
  "target": "./src",
  "total": {
    "lines": 13842,
    "nonEmpty": 11239,
    "comments": 2123
  },
  "perExtension": {
    ".ts": { "files": 34, "lines": 7200, "nonEmpty": 5800, "comments": 900 },
    ".js": { "files": 20, "lines": 3000, "nonEmpty": 2500, "comments": 200 }
  },
  "topLargest": [
    { "file": "src/App.tsx", "stats": { "lines": 1024, "nonEmpty": 800, "comments": 120, "extension": ".ts" } }
  ]
}

🛠 Development

Clone and build locally:

git clone https://github.com/amir-bagjani/loc-counter.git
cd loc-counter
npm install
npm run build

Run with ts-node (development mode):

npx ts-node src/loc-counter.ts ./my-project

🤝 Contributing

Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.


📄 License

MIT © Amir Bagjani