Package Exports
- rapid-fuzzy
Readme
rapid-fuzzy
Rust-powered fuzzy search and string distance for JavaScript/TypeScript.
Status: Work in progress. Not yet published to npm.
Features
- Fast: Up to 40x faster than fuse.js for large datasets (Rust + napi-rs)
- Universal: Works in Node.js (native), browsers (WASM), Deno, and Bun
- Zero JS dependencies: Pure Rust core with napi-rs bindings
- Type-safe: Full TypeScript support with auto-generated type definitions
- Drop-in: API compatible with popular fuzzy search libraries
Installation
npm install rapid-fuzzy
# or
pnpm add rapid-fuzzyRuntime-specific notes
- Node.js (>=20): Uses native bindings via napi-rs for best performance.
- Browser / Deno / Bun: Falls back to a WASM build automatically.
Usage
String Distance
import { levenshtein, jaroWinkler, sorensenDice } from 'rapid-fuzzy';
levenshtein('kitten', 'sitting'); // 3
jaroWinkler('MARTHA', 'MARHTA'); // 0.961
sorensenDice('night', 'nacht'); // 0.25Fuzzy Search
import { search, closest } from 'rapid-fuzzy';
// Find matches sorted by relevance
const results = search('typscript', [
'TypeScript',
'JavaScript',
'Python',
'TypeSpec',
]);
// → [{ item: 'TypeScript', score: 89, index: 0 }, ...]
// Find the single best match
closest('tsc', ['TypeScript', 'JavaScript', 'Python']);
// → 'TypeScript'Benchmarks
Measured on Apple M-series with Node.js v22 using Vitest bench. Each benchmark processes 6 realistic string pairs of varying length and similarity.
Distance Functions
| Function | rapid-fuzzy | fastest-levenshtein | leven | string-similarity |
|---|---|---|---|---|
| Levenshtein | 67,346 ops/s | 243,026 ops/s | 51,789 ops/s | — |
| Normalized Levenshtein | 64,592 ops/s | — | — | — |
| Sorensen-Dice | 61,050 ops/s | — | — | 40,241 ops/s |
| Jaro-Winkler | 198,140 ops/s | — | — | — |
| Damerau-Levenshtein | 58,888 ops/s | — | — | — |
Note: For single-pair Levenshtein distance, fastest-levenshtein is faster due to its highly optimized pure-JS implementation that avoids FFI overhead. rapid-fuzzy provides broader algorithm coverage and excels in batch / search scenarios.
Search Performance
| Dataset size | rapid-fuzzy | fuse.js | fuzzysort |
|---|---|---|---|
| 20 items | 171,967 ops/s | 121,978 ops/s | 2,537,323 ops/s |
| 1,000 items | 4,941 ops/s | 376 ops/s | 55,388 ops/s |
| 10,000 items | 588 ops/s | 14 ops/s | 15,005 ops/s |
Closest Match (Levenshtein-based)
| Dataset size | rapid-fuzzy | fastest-levenshtein |
|---|---|---|
| 1,000 items | 5,912 ops/s | 3,974 ops/s |
| 10,000 items | 387 ops/s | 126 ops/s |
rapid-fuzzy is up to 3x faster than fastest-levenshtein for closest-match lookups on large datasets.
Why these numbers matter
- vs fuse.js: rapid-fuzzy is 13x faster on medium datasets and 41x faster on large datasets for fuzzy search.
- vs fastest-levenshtein: rapid-fuzzy wins on closest-match (1.5–3x faster) where batch FFI overhead is amortized.
- fuzzysort uses a different (substring-based) matching algorithm that is extremely fast but produces different ranking results. Choose based on your matching needs.
Run benchmarks yourself:
pnpm run bench # JavaScript benchmarks
cargo bench # Rust internal benchmarksWhy rapid-fuzzy?
| rapid-fuzzy | fuse.js | fastest-levenshtein | fuzzysort | |
|---|---|---|---|---|
| Algorithms | Levenshtein, Jaro-Winkler, Sorensen-Dice, Damerau-Levenshtein, fuzzy search | Bitap-based fuzzy | Levenshtein only | Substring fuzzy |
| Runtime | Rust (native + WASM) | Pure JS | Pure JS | Pure JS |
| Batch API | Yes | No | No | No |
| Node.js native | Yes (napi-rs) | No | No | No |
| Browser support | Yes (WASM) | Yes | Yes | Yes |
| TypeScript | Full (auto-generated) | Full | Yes | Yes |
License
MIT