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

@leolee9086/longfile-detector

v1.0.0

Published

A high-performance CLI tool to detect and list text files with the most lines in a directory

Readme

Longfile Detector

一个高性能的命令行工具,用于检测并列示指定目录下行数最多的文本文件。

特性

  • 🚀 高性能: 使用 fast-glob 和优化的文件处理算法
  • 🔍 智能检测: 基于 mimedb 的 MIME 类型检测,准确识别文本文件
  • 🎯 灵活过滤: 支持 Glob 模式和扩展名过滤
  • 📊 详细信息: 显示文件行数、大小、类型和修改时间
  • 🛡️ 安全可靠: 完善的错误处理和边界情况处理
  • 📦 易于使用: 支持 npx 直接运行

安装

全局安装

npm install -g longfile-detector

使用 npx (推荐)

npx longfile-detector [选项]

本地安装

npm install longfile-detector

使用方法

基本用法

# 扫描当前目录,显示前10个最大的文本文件
npx longfile-detector

# 扫描指定目录
npx longfile-detector -d /path/to/directory

# 显示更多文件
npx longfile-detector -n 20

# 使用自定义 Glob 模式
npx longfile-detector -g "**/*.{js,ts,jsx,tsx}"

# 按扩展名过滤
npx longfile-detector -e "js,ts,jsx,tsx"

# 显示详细信息
npx longfile-detector -v

命令行选项

| 选项 | 简写 | 描述 | 默认值 | |------|------|------|--------| | --directory | -d | 要扫描的目录路径 | . (当前目录) | | --number | -n | 显示文件数量 | 10 | | --glob | -g | Glob 模式过滤文件 | **/*.{js,ts,jsx,tsx,html,css,scss,less,json,md,txt,yml,yaml} | | --extensions | -e | 文件扩展名过滤,逗号分隔 | - | | --verbose | -v | 显示详细信息 | false | | --help | -h | 显示帮助信息 | - | | --version | -V | 显示版本号 | - |

示例输出

正在扫描目录: ./src
使用 Glob 模式: **/*.{js,ts,jsx,tsx,html,css,scss,less,json,md,txt,yml,yaml}

检测结果 (按行数排序):
────────────────────────────────────────────────────────────────────────────────
  1.     1,234 行 (   45.67 KB) - src/components/large-component.js
  2.       987 行 (   32.15 KB) - src/utils/data-processor.ts
  3.       654 行 (   21.89 KB) - src/pages/dashboard.jsx
  4.       432 行 (   15.23 KB) - src/styles/main.scss
  5.       321 行 (   11.45 KB) - src/config/settings.json
────────────────────────────────────────────────────────────────────────────────
扫描完成,共处理 5 个文件,耗时 23.45 ms

支持的文件类型

工具会自动检测以下类型的文本文件:

编程语言

  • JavaScript (.js, .jsx)
  • TypeScript (.ts, .tsx)
  • Python (.py)
  • Java (.java)
  • C/C++ (.c, .cpp, .h, .hpp)
  • C# (.cs)
  • PHP (.php)
  • Ruby (.rb)
  • Go (.go)
  • Rust (.rs)
  • Swift (.swift)
  • Kotlin (.kt)
  • Scala (.scala)
  • R (.r)
  • Perl (.pl)
  • Lua (.lua)

Web 技术

  • HTML (.html, .htm)
  • CSS (.css, .scss, .sass, .less)
  • JSON (.json)
  • XML (.xml)
  • YAML (.yml, .yaml)

文档

  • Markdown (.md)
  • 纯文本 (.txt)
  • 配置文件 (.ini, .conf)

其他

  • Shell 脚本 (.sh, .bash)
  • SQL (.sql)
  • 日志文件 (.log)
  • Dockerfile
  • Makefile
  • Git 配置文件 (.gitignore, .gitattributes)

性能优化

  • 并行处理: 使用 Promise.all 并行处理多个文件
  • 高效行数计算: 直接操作 Buffer,避免字符串分割
  • 智能过滤: 基于 MIME 类型的准确文件类型检测
  • 内存优化: 流式处理大文件,避免内存溢出
  • 缓存优化: 使用 fast-glob 的高效文件系统遍历

错误处理

工具具有完善的错误处理机制:

  • 自动跳过无法读取的文件
  • 忽略二进制文件和非文本文件
  • 处理权限问题
  • 提供详细的错误信息(使用 -v 选项)

开发

本地开发

# 克隆仓库
git clone <repository-url>
cd longfile-detector

# 安装依赖
npm install

# 运行测试
npm test

# 代码检查
npm run lint

# 本地运行
node bin/longfile-detector.js

测试

# 运行所有测试
npm test

# 运行特定测试
node --test test/detector.test.js

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

v1.0.0

  • 初始版本发布
  • 支持基本的文件检测功能
  • 添加 Glob 模式过滤
  • 实现高性能行数计算
  • 添加详细的测试用例