fast-fuzzy is a compact and high-performance JavaScript utility for fuzzy string matching, currently at version 1.12.0. It implements a modified Levenshtein distance algorithm, specifically Damerau-Levenshtein distance, which is more forgiving of transpositions. The library preprocesses inputs through UTF-8 normalization, optional lowercasing, symbol stripping, and whitespace normalization to ensure robust matching. It scores matches between 0 and 1, returning results sorted by score, then by match earliness, and finally by length proximity to the search term. For efficiency, especially when searching the same set of candidates repeatedly, it internally uses a trie data structure to cache work and prune non-matching subtrees, significantly outperforming brute-force approaches. While it offers a simple `search` function for one-off queries, the `Searcher` class is recommended for persistent collections due to its trie caching. The project appears to have a steady, though not strictly scheduled, release cadence, with ongoing maintenance.
npm install fast-fuzzyVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing a `Searcher` with complex objects and a `keySelector`, performing a fuzzy search, and dynamically adding new candidates, with results filtered by a threshold.
For repeated searches against a consistent set of candidates, instantiate and reuse the `Searcher` class. Its internal trie is cached and updated incrementally, providing significantly better performance.
Review and override the default options (`ignoreCase: true`, `ignoreSymbols: true`, `normalizeWhitespace: true`) in the `options` object passed to `search` or `Searcher` constructor if specific normalization behaviors are not desired.
When searching `Object[]` arrays, ensure `keySelector` is a function that returns the string(s) to be searched from each object. It can return a single string or an array of strings (e.g., `item => [item.name, item.description]`).
Adjust the `threshold` option to a lower value (e.g., `0.4` or `0`) in the `options` object passed to `search` or `Searcher` to include more fuzzy matches. A lower threshold will also increase the number of results and potentially search time.
Ensure that your `keySelector` function correctly returns a string or an array of strings for every candidate, and that the properties it accesses exist on all candidate objects. Add defensive checks if some properties might be missing.
Check the `threshold` option and consider lowering it. Verify that the `keySelector` correctly extracts search strings from your candidates. Also, review `ignoreCase`, `ignoreSymbols`, and `normalizeWhitespace` options to ensure they align with your search requirements.
Refactor your code to use the `Searcher` class. Initialize a `Searcher` instance once with your candidate list, and then call its `search` method repeatedly. Use `add` or re-instantiate if the candidate list changes significantly.
No dependency data recorded yet.