FZF Fuzzy Matching Algorithm for JavaScript

0.5.2 · active · verified Sun Apr 19

FZF for JavaScript is a library that ports the core fuzzy-finding algorithm from the popular FZF CLI tool into a JavaScript-native implementation, making it suitable for both browser and Node.js environments. The current stable version is `v0.5.2`. The project exhibits an active development cadence, with frequent minor releases that, while in `0.x` territory, introduce significant features and occasionally breaking changes. It differentiates itself by offering two distinct fuzzy algorithms (`v1` for speed, `v2` for better highlighting), support for extended search syntax, and an asynchronous finder for maintaining a responsive user interface during complex queries. This library is specifically designed to power command palettes and similar interactive search UIs in modern web applications, providing a robust and performant fuzzy matching experience.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes `Fzf` with a list of strings and performs a basic fuzzy search, demonstrating how to retrieve and iterate over the sorted results.

import { Fzf } from 'fzf';

const programmingLanguages = [
  'go', 'javascript', 'python', 'rust', 
  'swift', 'kotlin', 'elixir', 'java', 
  'lisp', 'v', 'zig', 'nim', 'rescript', 
  'd', 'haskell'
];

// Create a new Fzf instance with your list of items
const fzf = new Fzf(programmingLanguages, {
  tiebreakers: ['end', 'length'], // Example option, uses 'end' and 'length' as secondary sort keys
  limit: 5 // Limit the number of results
});

// Perform a fuzzy search
const query = 'jav';
const entries = fzf.find(query);

console.log(`Fuzzy search results for '${query}':`);
entries.forEach(entry => {
  console.log(`- ${entry.item} (Score: ${entry.score})`);
});
// Expected output: javascript, java (order depends on scores and tiebreakers)

view raw JSON →