@rasmx/fuzzy
v1.0.0
Published
Blazing fast WASM fuzzy search library powered by Rust and Nucleo matcher. Optimized for performance and high-quality matching.
Maintainers
Readme
@rasmx/fuzzy
Blazing fast fuzzy search library powered by Rust and WebAssembly. Optimized for performance using the nucleo matcher.
Features
- High Performance: Powered by Rust's
nucleo-matcher. - Smart Matching: Supports smart-case and normalization by default.
- Highlighting: Built-in utility to highlight matched characters.
- Stateful Index: Efficiently handle large datasets without re-copying strings to WASM memory.
- Rich Results: Returns scores and character indices for custom UI rendering.
Installation
pnpm add @rasmx/fuzzyUsage
Basic Usage
import init, { fuzzy } from '@rasmx/fuzzy';
await init();
const list = ["apple", "banana", "apricot", "peach"];
const results = fuzzy.search("ap", list);
results.forEach(res => {
const text = list[res.idx];
console.log(fuzzy.highlight(text, res.indices));
});Stateful Index (Large Datasets)
import init, { FuzzyIndex } from '@rasmx/fuzzy';
await init();
const index = new FuzzyIndex();
index.addBulk(["huge", "list", "of", "strings", "..."]);
const results = index.search("str");API Reference
fuzzy
search(query, list, limit?): ReturnsSearchResult[].highlight(text, indices, prefix?, suffix?): Returnsstring.
FuzzyIndex
add(text): Adds a single string to the index.addBulk(list): Adds an array of strings.search(query, limit?): Performs a search on the indexed data.clear(): Clears the internal storage.free(): Manually release WASM memory.
SearchResult
idx: Index in the original array.score: Match score (higher is better).indices: Array of character positions that matched the query.
License
MIT
