@omerdev/fuzzy-finder
v1.0.1
Published
Nano-fast fuzzy search and autocomplete scoring algorithm with typo tolerance and zero dependencies (<1KB)
Maintainers
Readme
🔎 @omerdev/fuzzy-finder
Nano-fast fuzzy search and autocomplete scoring algorithm with typo tolerance and zero dependencies (<1KB).
⚡ Why fuzzy-finder?
- Zero Dependencies: Sub-1KB footprint with zero runtime dependencies.
- Smart Scoring: Consecutive match bonuses, word boundary recognition (slugs, camelCase, path separators), and compactness weighting.
- Object Search: Search through complex object arrays by specifying keys or custom getter functions.
- Highlighting: Built-in contiguous tag wrapper for instant UI search rendering (
<mark>foo</mark>). - Blazing Speed: Optimized forward scan capable of scoring millions of items per second.
📦 Installation
npm install @omerdev/fuzzy-finder
# or
pnpm add @omerdev/fuzzy-finder
# or
bun add @omerdev/fuzzy-finder💡 Quick Start
1. Fuzzy Match & Score
import { fuzzyMatch } from "@omerdev/fuzzy-finder";
const res = fuzzyMatch("fb", "foo_bar");
console.log(res);
// { matched: true, score: 0.85, matches: [0, 4] }2. Search Lists or Objects
import { fuzzySearch } from "@omerdev/fuzzy-finder";
const files = [
"src/components/ButtonDropdown.tsx",
"src/components/Button.tsx",
"src/components/ButtonGroup.tsx",
];
const results = fuzzySearch("Button", files);
// Sorted by relevance: Button.tsx -> ButtonGroup.tsx -> ButtonDropdown.tsx
// Searching structured objects:
const users = [
{ id: 1, name: "Alice Adams", email: "[email protected]" },
{ id: 2, name: "Bob Brown", email: "[email protected]" },
];
const found = fuzzySearch("ali", users, { keys: ["name", "email"] });3. Match Highlighting
import { highlight, fuzzyMatch } from "@omerdev/fuzzy-finder";
const text = "Application";
const match = fuzzyMatch("app", text);
const html = highlight(text, match.matches, "<mark>", "</mark>");
// "<mark>App</mark>lication"👤 Author
omerdev
📄 License
MIT
