Skip to content

Getting started

rapid-fuzzy is a fuzzy search and string similarity library for JavaScript and TypeScript. Its core is written in Rust: Node.js loads it as a native addon, and browsers, Deno, Bun and Cloudflare Workers can load it as WebAssembly. The API is the same everywhere.

Terminal window
npm install rapid-fuzzy

Node.js 22 or later is required. Prebuilt native binaries are installed automatically for macOS, Linux (glibc and musl) and Windows, on x64 and arm64. Bundlers pick the WebAssembly build for the browser on their own: see Runtimes below.

import { search, closest } from 'rapid-fuzzy';
const languages = ['TypeScript', 'JavaScript', 'Python', 'Rust', 'Go'];
search('typscript', languages);
// → [{ item: 'TypeScript', score: 0.86, index: 0, positions: [] }]
closest('rst', languages); // → 'Rust'

Results are sorted by relevance, and scores run from 0 to 1. Queries understand a small syntax: ^prefix, suffix$, 'exact, !exclude, and several space-separated terms that can appear in any order.

For autocomplete, command palettes and file finders, build a FuzzyIndex once. It keeps the items in Rust and is about 10x faster per query than search() on 1,000 to 10,000 items:

import { FuzzyIndex } from 'rapid-fuzzy';
const index = new FuzzyIndex(languages);
index.search('typscript', { maxResults: 5 });
index.add('Zig');
index.destroy(); // free the Rust-side memory when you are done
import { searchObjects } from 'rapid-fuzzy';
const users = [
{ name: 'John Smith', email: 'john@example.com' },
{ name: 'Jane Doe', email: 'jane@example.com' },
];
searchObjects('jane', users, {
keys: [{ name: 'name', weight: 2 }, 'email'],
});
// → [{ item: { name: 'Jane Doe', … }, index: 1, score: 1, keyScores: [1, 1] }]
import { levenshtein, jaroWinkler, tokenSortRatio } from 'rapid-fuzzy';
levenshtein('kitten', 'sitting'); // 3
jaroWinkler('MARTHA', 'MARHTA'); // 0.961
tokenSortRatio('New York Mets', 'Mets New York'); // 1

Seven distance metrics and four token-based ratios are included. Each has *Batch and *Many variants for comparing many strings in one call. See String similarity.

  • Try it in the Playground, which runs the WebAssembly build in your browser.
  • Read How matching works before you pick a minScore.
  • Coming from another library? There are migration guides for fuse.js, fuzzysort, uFuzzy, fuzzball, leven and others.