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

code-line-exporter

v1.0.2

Published

This npm package will be used to count the number of lines of code.

Readme

Node 项目使用文档

项目概述

本项目是一个 Node.js 应用程序,旨在统计指定目录(包括其子目录)中所有文件的代码行数、注释行数、空行数以及总行数,并能生成详细的统计报告。通过简单的命令行参数,用户可以灵活控制输出结果的格式、 ~~是否导出结果~~(默认导出)、以及排除特定的目录或文件。

主要功能

  • 代码行数统计:统计指定目录中所有有效代码的行数。
  • 注释行数统计:统计指定目录中所有注释的行数。
  • 空行数统计:统计指定目录中所有的空行数。
  • 总行数统计:统计指定目录中所有行的总数。
  • 详细报告生成:生成包含编程语言分布、文件分布以及目录分布的详细报告。
  • 自定义排除:支持通过命令行参数排除特定的目录或文件。
  • 结果导出:支持将统计结果导出到默认为程序运行目录下的outputFiles文件夹中。
  • 文件类型过滤:支持指定特定的文件类型进行统计,如 .js.py 文件。

支持的文件类型

本项目支持以下常见编程语言的文件类型:

| 文件类型 | 编程语言 | |----------|---------------| | js | JavaScript | | py | Python | | java | Java | | xml | XML | | html | HTML | | lua | Lua | | cs | C# | | php | PHP | | css | CSS | | vue | Vue | | ts | TypeScript | | go | Go | | c | C | | cpp | C++ | | h | C/C++ Header | | cc | C++ | | inl | C++ Inline | | rs | Rust |


安装与依赖

安装 Node.js 和 npm

要运行本项目,需确保已安装 Node.js 和 npm(Node 包管理器)。如尚未安装,请从 Node.js 官方网站 下载并安装最新版本的 Node.js 和 npm。

安装项目依赖

在项目根目录下运行以下命令以安装项目依赖:

npm install code-line-reporter

使用方法

在项目根目录下,通过终端运行以下命令来统计指定目录的代码行数等信息:

code-line-reporter <路径> [--summary] [--export] [--exclude <排除目录1> <排除目录2> ...] [--type <文件类型>]

或者通过以下命令来获得帮助:

code-line-reporter --help

其中:

  • <路径>:要统计的目录路径。
  • --summary:可选参数,用于控制是否简化输出结果。若指定此参数,则仅显示总计信息。
  • ~~--export:可选参数,用于控制是否将结果导出到 output.txt 文件中。若指定此参数,则结果将被导出到该文件。~~(默认导出)
  • --exclude:可选参数,用于排除特定的目录或文件。可指定多个排除目录或文件,它们之间用空格分隔。
  • --type:可选参数,用于指定要统计的文件类型,如 jspy。可指定多个文件类型,它们之间用空格分隔。

示例

  • 统计当前目录下的所有文件的代码行数等信息,并简化输出结果:

    code-line-reporter --summary

~~- 统计指定目录(例如 F:\node_pkg)的代码行数等信息,并将结果导出到 output.txt 文件中:~~

~~bash~~ ~~code-line-reporter F:\node_pkg --export~~ ~~~~

  • 统计指定目录(例如 F:\node_pkg)的代码行数等信息,排除 testbuild 目录:

    code-line-reporter F:\node_pkg --exclude test build
  • 统计指定目录(例如 F:\node_pkg)的代码行数等信息,仅统计 .js.py 文件:

    code-line-reporter F:\node_pkg --type js py

    注意:上述命令中的参数和路径可根据实际情况进行调整,且参数之间可组合使用。

输出示例

  • 默认输出:不使用 --summary 参数时,程序将输出每个文件的详细统计信息,包括文件路径、编程语言、有效行数、注释行数、空行数以及总行数。此外,还会输出总计信息。
  • 简化输出:使用 --summary 参数时,程序将仅输出总计信息,包括文件数、有效行数、注释行数、空行数以及总行数。
  • ~~导出输出:使用 --export 参数时,程序将上述输出(默认输出或简化输出)保存到 output.txt 文件中。~~
  • 指定统计类型文件:使用 --type 参数时,程序将统计目录下指定文件类型。

注意事项

  • 确保指定的目录路径存在且可读。
  • 如果要排除特定的目录或文件,请确保它们的路径正确。
  • 文件类型参数(--type)支持多个文件类型,它们之间用空格分隔,无需指定文件后缀的点(.)。