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

repe

v0.1.0

Published

重复代码检测工具

Readme

Repe

repe 是 repeat 的简写, 意为 "重复" , 它是用于比较文件重复度的CLI工具。

功能特性

  • 🔍 智能文件匹配: 自动识别两个目录中相同路径下的相同文件
  • 📊 相似度计算: 使用先进的字符串相似度算法计算文件内容的重复度
  • 🖼️ 图片支持: 支持图片文件的比较(基于MD5哈希值)
  • 📈 简洁统计: 提供精炼的统计信息,避免信息过载
  • 🎯 阈值过滤: 支持设置最小相似度阈值,只显示符合条件的文件
  • 📋 详细模式: 可选的详细显示模式,按文件类型分类展示重复文件
  • 🎨 颜色标记: 完全相同的文件用红色高亮显示

安装

npm install repe -g

支持的文件类型

文本文件

  • 所有文本格式文件(.txt, .js, .ts, .py, .md, .json, .xml, .html, .css 等)

图片文件

  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • GIF (.gif)
  • BMP (.bmp)
  • WebP (.webp)
  • SVG (.svg)
  • ICO (.ico)
  • TIFF (.tiff, .tif)

使用方法

基本用法

# 比较两个目录(包含文本和图片文件)
repe compare <目录1> <目录2>

# 示例
repe compare ./src/intl ./src/cn

高级选项

# 设置最小相似度阈值 (0-1)
repe compare ./src ./backup --min-similarity 0.8

# 仅比较文本文件
repe compare ./src ./backup --text-only

# 显示详细的重复文件信息
repe compare ./src ./backup --details

# 组合使用
repe compare ./src ./backup --min-similarity 0.7 --details

命令行选项

  • -m, --min-similarity <number>: 最小相似度阈值 (0-1),默认为 0
  • -t, --text-only: 仅比较文本文件
  • -d, --details: 显示详细的重复文件信息
  • -i, --include-images: 包含图片文件比较 (默认已启用)
  • -h, --help: 显示帮助信息
  • -v, --version: 显示版本信息

输出说明

基本输出模式

默认情况下,repe 提供简洁的统计信息:

  • 目录文件总数: 显示两个目录的文件总数及文本/图片文件分布
  • 文件路径重复: 显示相同路径文件的数量和重复度
  • 满足阈值文件数: 显示符合相似度阈值的文件数量
  • 图片相同数: 显示完全相同的图片文件数量
  • 文本文件平均相似度: 显示相同路径下文本文件的平均相似度

详细显示模式 (--details)

使用 --details 选项可以查看详细的重复文件信息:

  • 按文件类型分类: 文本文件和图片文件分别显示
  • 相似度信息前置: 相似度或状态信息用方括号显示在文件路径前
  • 红色高亮: 完全相同的文件(100%文本或相同图片)用红色显示

图片比较说明

  • 图片文件使用MD5哈希值进行比较
  • 哈希值相同表示图片内容完全相同,显示"相同"
  • 哈希值不同表示图片内容不同,显示"不同"

基本输出示例

比较 ./test-dir1 和 ./test-dir2 :

找到 4 个符合相似度条件的文件
其中 2 个文件完全相同

=== 统计结果 ===
目录1文件总数: 5 (文本: 3, 图片: 2)
目录2文件总数: 5 (文本: 3, 图片: 2)
文件路径有: 4 个重复, 重复度为: 80.00%
满足阈值文件数: 4 (文本: 2, 图片: 2)
图片相同数: 1
相同路径下文本文件平均相似度: 97.01%

详细输出示例 (--details)

比较 ./test-dir1 和 ./test-dir2 :

找到 4 个符合相似度条件的文件
其中 2 个文件完全相同

=== 重复文件详情 ===

文本文件:
  [100.00%] file1.txt                    *(红色显示)*
  [94.02%] file2.js

图片文件:
  [相同] images/logo.png                 *(红色显示)*
  [不同] images/icon.png

=== 统计结果 ===
目录1文件总数: 5 (文本: 3, 图片: 2)
目录2文件总数: 5 (文本: 3, 图片: 2)
文件路径有: 4 个重复, 重复度为: 80.00%
满足阈值文件数: 4 (文本: 2, 图片: 2)
图片相同数: 1
相同路径下文本文件平均相似度: 97.01%

使用场景

  1. 代码备份验证: 验证备份文件与原始文件的完整性
  2. 代码重构检查: 检查重构后的代码与原始代码的相似度
  3. 版本对比: 比较不同版本间的代码变化
  4. 代码重复检测: 发现项目中的重复代码片段
  5. 文件同步验证: 验证文件同步工具的正确性
  6. 图片资源管理: 检查图片文件是否被修改或替换
  7. 媒体文件备份: 验证图片备份的完整性

技术实现

  • 文件遍历: 递归遍历目录结构,获取所有文件路径
  • 文本相似度算法: 使用 Dice's coefficient 算法计算字符串相似度
  • 图片比较: 使用MD5哈希值比较图片文件的二进制内容

开发

# 开发模式 (监听文件变化)
pnpm dev

# 构建项目
pnpm build

# 运行测试
pnpm test

# 代码检查
pnpm lint