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"
Or individual crates:
Cargo.toml
[dependencies]
cpd-core = "0.1"
cpd-tokenizer = "0.1"
cpd-reporter = "0.1"
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
13 built-in reporters: console, console-full, json, xml, csv, html, markdown, sarif, 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
- gitoxide blame — in-process git blame (no shelling out to
git) - Cross-format detection — Vue SFC, Svelte, Astro, Markdown
v4 Node.js Packages
If you're using v4 (TypeScript), the equivalent packages are:
| v5 Rust Crate | v4 npm Package |
|---|---|
cpd | jscpd |
cpd-core | @jscpd/core |
cpd-tokenizer | @jscpd/tokenizer |
cpd-finder | @jscpd/finder |
cpd-reporter | @jscpd/html-reporter, @jscpd/badge-reporter, @jscpd/sarif-reporter |
See the Migration Guide for details on upgrading from v4 packages.