code-stats

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Statistics

代码统计

Quickly analyze codebase size, composition, and changes.
快速分析代码库的规模、构成及变更情况。

tokei - Line Counts

tokei - 代码行数统计

bash
undefined
bash
undefined

Count all code

统计所有代码

tokei
tokei

Compact output sorted by code

按代码量排序的精简输出

tokei --compact --sort code
tokei --compact --sort code

Specific languages

指定编程语言

tokei --type=TypeScript,JavaScript
tokei --type=TypeScript,JavaScript

Exclude directories

排除目录

tokei --exclude node_modules --exclude dist
tokei --exclude node_modules --exclude dist

JSON output for scripting

生成JSON输出用于脚本处理

tokei --output json | jq '.Total.code'
undefined
tokei --output json | jq '.Total.code'
undefined

Sample Output

示例输出

===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 TypeScript             45        12847         9823         1456         1568
 JavaScript             12         2341         1876          234          231
-------------------------------------------------------------------------------
 Total                  57        15188        11699         1690         1799
===============================================================================
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 TypeScript             45        12847         9823         1456         1568
 JavaScript             12         2341         1876          234          231
-------------------------------------------------------------------------------
 Total                  57        15188        11699         1690         1799
===============================================================================

difft - Semantic Diffs

difft - 语义化差异对比

bash
undefined
bash
undefined

Compare files

对比文件

difft old.ts new.ts
difft old.ts new.ts

Inline mode

行内模式

difft --display=inline old.ts new.ts
difft --display=inline old.ts new.ts

With git

与Git结合使用

GIT_EXTERNAL_DIFF=difft git diff GIT_EXTERNAL_DIFF=difft git show HEAD~1
undefined
GIT_EXTERNAL_DIFF=difft git diff GIT_EXTERNAL_DIFF=difft git show HEAD~1
undefined

Why Semantic?

为什么选择语义化对比?

Traditional diffdifft
Line-by-lineAST-aware
Shows moved as delete+addRecognizes moves
Whitespace sensitiveIgnores formatting
传统差异对比difft
逐行对比基于AST识别
将移动代码显示为删除+添加可识别代码移动
对空白字符敏感忽略格式变化

Quick Reference

快速参考

TaskCommand
Count all code
tokei
Compact output
tokei --compact
Sort by code
tokei --sort code
TypeScript only
tokei -t TypeScript
JSON output
tokei --output json
Exclude dir
tokei --exclude node_modules
Semantic diff
difft file1 file2
Git diff
GIT_EXTERNAL_DIFF=difft git diff
任务命令
统计所有代码
tokei
精简输出
tokei --compact
按代码量排序
tokei --sort code
仅统计TypeScript
tokei -t TypeScript
生成JSON输出
tokei --output json
排除目录
tokei --exclude node_modules
语义化差异对比
difft file1 file2
Git差异对比
GIT_EXTERNAL_DIFF=difft git diff

When to Use

使用场景

  • Getting quick codebase overview
  • Comparing code changes semantically
  • Understanding project composition
  • Reviewing refactoring impact
  • Tracking codebase growth
  • 快速了解代码库概况
  • 语义化对比代码变更
  • 分析项目构成
  • 评估重构影响
  • 跟踪代码库增长情况

Additional Resources

额外资源

For detailed patterns, load:
  • ./references/tokei-advanced.md
    - Filtering, output formats, CI integration
  • ./references/difft-advanced.md
    - Display modes, git integration, language support
如需详细用法,请查看:
  • ./references/tokei-advanced.md
    - 过滤规则、输出格式、CI集成
  • ./references/difft-advanced.md
    - 显示模式、Git集成、语言支持