FuzzySort (fuzzysort) is a JavaScript library providing a fast, SublimeText-like fuzzy searching algorithm. It is designed for high performance, capable of searching thousands of items in under 1ms, while maintaining a small footprint (5kb, 0 dependencies). The current stable version is 3.1.0, with updates released as needed for performance improvements or bug fixes rather than a strict schedule. Key differentiators include its speed, minimal size, and an intuitive API for both simple string matching and complex object searching with multiple keys and custom scoring functions. It offers robust result objects that include score, target, original object reference, and index highlights, enabling rich UI feedback. It ships with TypeScript types for enhanced developer experience.
npm install fuzzysortVerified import paths — ran on the pinned version, not inferred.
This example demonstrates both basic and advanced fuzzy searching for a list of objects. It shows how to search by a single key, multiple keys, and how to apply a custom score function to boost results based on object properties. It also illustrates how to use the `highlight` method on results.
`targets.forEach(t => t.preparedString = fuzzysort.prepare(t.originalString));` then search `fuzzysort.go('query', targets, {key: 'preparedString'});`Pre-filter your target list: `targets = targets.filter(t => t.file.length < 1000);` or consider pre-processing to extract relevant, shorter snippets for searching.
Always use `{ key: 'yourKeyName' }` or `{ keys: ['key1', 'key2'] }` when searching an array of objects if you need to access the original object data in the results.For UI frameworks, use `result.highlight((match, index) => <span key={index} className="highlight">{match}</span>)` instead of `result.highlight('<b>', '</b>')` to generate framework-specific elements.Access `target` and `indexes` for a specific key match via its index, e.g., `keysResult[0].target` or `keysResult[1].highlight()`.
For ESM, use `import fuzzysort from 'fuzzysort';`. For CommonJS, use `const fuzzysort = require('fuzzysort');`. Ensure you are not trying `import { go } from 'fuzzysort';`.For browsers, add `<script src="https://cdn.jsdelivr.net/npm/fuzzysort@3.0.2/fuzzysort.min.js"></script>` to your HTML. For Node.js, ensure `npm i fuzzysort` is run and use `import fuzzysort from 'fuzzysort'` or `const fuzzysort = require('fuzzysort')`.Ensure you provide the `key` option (e.g., `{ key: 'name' }`) or `keys` option (e.g., `{ keys: ['name', 'description'] }`) when searching objects, and verify the key path exists on your target objects.No dependency data recorded yet.