API
Rust Crates (v5)
Use jscpd's Rust crates for custom integrations.
Installation
Add to your Cargo.toml:
Cargo.toml
[dependencies]
cpd-finder = "0.1.13"
Or individual crates:
Cargo.toml
[dependencies]
cpd-core = "0.1.10"
cpd-tokenizer = "0.1.12"
cpd-reporter = "0.1.11"
cpd-core
The core Rabin-Karp rolling hash detection algorithm.
use cpd_core::detect;
// Detect clones from tokenized input
cpd-tokenizer
Source code tokenizer with OXC-based JS/TS/JSX/TSX tokenization and generic line-based tokenization for 223 other formats.
use cpd_tokenizer::tokenize;
// Tokenize source code into detection-ready format
cpd-finder
Full orchestration pipeline — file walking, tokenization, detection, and statistics.
use cpd_finder::orchestrate;
fn main() {
let result = orchestrate(&["./src".into()], &Default::default());
println!("Found {} clones", result.statistics.total_clones);
println!("Duplication: {:.1}%", result.statistics.total_percentage);
}
cpd-reporter
15 built-in reporters: console, console-full, json, xml, csv, html, markdown, sarif, openmetrics, codeclimate, ai, badge, xcode, threshold, silent.
Features
- Pure Rust — no external runtime required
- Parallel detection — uses
rayonfor detection across format groups - OXC tokenization — fast, accurate JS/TS/JSX/TSX parsing
- Git blame enrichment — per-line author data via
git blame --porcelain - Cross-format detection — Vue SFC, Svelte, Astro, Markdown
Coming from the v4 @jscpd/* npm packages? The Migration Guide maps each one to its Rust crate.