Linguisto
Introduction
Linguisto is a high-performance code language analysis tool based on github-linguist. Built with Rust and providing Node.js bindings via NAPI-RS, it quickly scans directories to count files, calculate byte sizes, and determine language percentages, while intelligently filtering out third-party dependencies and ignored files.
Features
- Superior Performance: Written in Rust, leveraging multi-threading for fast file system traversal.
- Smart Filtering: Automatically respects
.gitignore, skips hidden files, and excludes vendored files (e.g.,node_modules). - Precise Detection: Based on robust language detection algorithms, supporting filename, extension, and content-based disambiguation.
- Beautiful Output: Provides a colorful terminal UI with progress bars, supporting sorting by bytes or file count.
- Data Integration: Supports JSON output for easy integration with other tools.
- Cross-platform: Supports macOS, Linux, Windows, and WASI environments.
Table of Contents
Install
For CLI
If you have Rust installed, you can install it via Cargo:
Or install it globally via npm:
For API
Install it as a dependency in your Node.js project:
Usage
CLI Usage
Run it in the current directory to see an intuitive language distribution chart (sorted by byte size by default):
Analyze a specific directory:
Common Options
--json: Output results in JSON format.--all: Show all detected files (by default, it only shows programming languages and filters out some configuration files).--sort <type>: Sort results.typecan befile_count(descending) orbytes(descending, default).
Example
# Get JSON stats for the current project sorted by file count
Programmatic Usage
You can call the API provided by @homy/linguist directly in your Node.js or TypeScript code.
const = require;
// Analyze specific directory
const stats = ;
console.log;
References
analyzeDirectory(dir)
- Type:
(dir: string) => LanguageStat[]
Analyzes the target directory and returns an array of language statistics.
LanguageStat
Each statistical object contains the following fields:
| Field | Type | Description |
|---|---|---|
lang |
string |
Detected language name (e.g., "Rust", "TypeScript") |
count |
number |
Number of files for this language |
bytes |
bigint |
Total bytes occupied by files of this language |
ratio |
number |
Percentage in the overall project (0.0 - 1.0) |
isProgramming |
boolean |
Whether it is a programming language |
Credits
- github-linguist/linguist - The project that inspired this tool and provides the language detection logic.
- drshade/linguist - A Rust implementation of linguist that served as a reference.