Convert Figma logo to code with AI

bevacqua logofuzzysearch

:crystal_ball: Tiny and blazing-fast fuzzy search in JavaScript

2,711
87
2,711
5

Quick Overview

The bevacqua/fuzzysearch project is a lightweight and efficient fuzzy search library for JavaScript. It provides a simple and customizable way to perform fuzzy string matching, which can be useful in a variety of applications, such as autocomplete, search engines, and data analysis.

Pros

  • Lightweight: The library is small in size, making it suitable for use in performance-sensitive applications.
  • Customizable: The library allows for a high degree of customization, enabling users to fine-tune the fuzzy search algorithm to their specific needs.
  • Fast: The library is designed to be fast and efficient, with a focus on performance.
  • Flexible: The library can be used in a variety of environments, including the browser, Node.js, and other JavaScript-based platforms.

Cons

  • Limited Features: The library is relatively simple and may not provide all the features that some users might require, such as advanced scoring algorithms or support for multiple languages.
  • Lack of Documentation: The project's documentation could be more comprehensive, which may make it more difficult for new users to get started.
  • Potential Maintenance Issues: The project has not been actively maintained for several years, which could be a concern for some users who require ongoing support and updates.
  • Potential Compatibility Issues: As the project has not been actively maintained, there may be compatibility issues with newer versions of JavaScript or related technologies.

Code Examples

Here are a few examples of how to use the bevacqua/fuzzysearch library:

import { fuzzy } from 'fuzzysearch';

// Basic fuzzy search
const result = fuzzy('foo', 'foobar'); // true

// Customizing the fuzzy search
const result = fuzzy('foo', 'foobar', {
  caseSensitive: true,
  returnWinningIndices: true
});
// { result: true, indices: [0, 1, 2, 3] }

// Using the fuzzy search with an array
const items = ['foo', 'bar', 'baz'];
const matches = items.filter(item => fuzzy('fo', item));
// ['foo']

Getting Started

To get started with the bevacqua/fuzzysearch library, follow these steps:

  1. Install the library using npm or yarn:
npm install fuzzysearch
  1. Import the fuzzy function from the library:
import { fuzzy } from 'fuzzysearch';
  1. Use the fuzzy function to perform fuzzy searches:
const result = fuzzy('foo', 'foobar'); // true
  1. Customize the fuzzy search by passing an options object as the fourth argument:
const result = fuzzy('foo', 'foobar', {
  caseSensitive: true,
  returnWinningIndices: true
});
// { result: true, indices: [0, 1, 2, 3] }
  1. Use the fuzzy search with an array of items:
const items = ['foo', 'bar', 'baz'];
const matches = items.filter(item => fuzzy('fo', item));
// ['foo']

That's the basic getting started guide for the bevacqua/fuzzysearch library. For more advanced usage and customization, please refer to the project's documentation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

fuzzysearch

Tiny and blazing-fast fuzzy search in JavaScript

Fuzzy searching allows for flexibly matching a string with partial input, useful for filtering data very quickly based on lightweight user input.

Demo

To see fuzzysearch in action, head over to bevacqua.github.io/horsey, which is a demo of an autocomplete component that uses fuzzysearch to filter out results based on user input.

Install

From npm

npm install --save fuzzysearch

fuzzysearch(needle, haystack)

Returns true if needle matches haystack using a fuzzy-searching algorithm. Note that this program doesn't implement levenshtein distance, but rather a simplified version where there's no approximation. The method will return true only if each character in the needle can be found in the haystack and occurs after the preceding matches.

fuzzysearch('twl', 'cartwheel') // <- true
fuzzysearch('cart', 'cartwheel') // <- true
fuzzysearch('cw', 'cartwheel') // <- true
fuzzysearch('ee', 'cartwheel') // <- true
fuzzysearch('art', 'cartwheel') // <- true
fuzzysearch('eeel', 'cartwheel') // <- false
fuzzysearch('dog', 'cartwheel') // <- false

An exciting application for this kind of algorithm is to filter options from an autocomplete menu, check out horsey for an example on how that might look like.

But! RegExps...!

chart showing abysmal performance for regexp-based implementation

The current implementation uses the algorithm suggested by Mr. Aleph, a crazy russian compiler engineer working at V8.

License

MIT

NPM DownloadsLast 30 Days