Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bevacqua/fuzzysearch
:crystal_ball: Tiny and blazing-fast fuzzy search in JavaScript
https://github.com/bevacqua/fuzzysearch
Last synced: 29 days ago
JSON representation
:crystal_ball: Tiny and blazing-fast fuzzy search in JavaScript
- Host: GitHub
- URL: https://github.com/bevacqua/fuzzysearch
- Owner: bevacqua
- License: mit
- Created: 2015-03-03T19:52:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-05-31T04:51:39.000Z (over 1 year ago)
- Last Synced: 2024-05-22T03:03:24.296Z (6 months ago)
- Language: JavaScript
- Homepage: https://ponyfoo.com
- Size: 14.6 KB
- Stars: 2,705
- Watchers: 43
- Forks: 86
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-blazingly-fast - fuzzysearch - :crystal_ball: Tiny and blazing-fast fuzzy search in JavaScript (JavaScript)
- awesome-tiny-js - fuzzysearch - One string at a time, does not compute score / rank. <img align="top" height="24" src="./img/fuzzysearch.svg"> (Text Search / Fuzzy search)
- awesome-list - fuzzysearch - fast fuzzy search in JavaScript | bevacqua | 2574 | (JavaScript)
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][3], which is a demo of an autocomplete component that uses `fuzzysearch` to filter out results based on user input.
# Install
From `npm`
```shell
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][2]_, 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.
```js
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][3] for an example on how that might look like.
# But! _`RegExp`s...!_
[![chart showing abysmal performance for regexp-based implementation][1]][4]
The current implementation uses the algorithm suggested by Mr. Aleph, a crazy russian compiler engineer working at V8.
# License
MIT
[1]: https://cloud.githubusercontent.com/assets/934293/6550014/d3a86174-c5fc-11e4-8334-b2e2b0d38fad.png
[2]: http://en.wikipedia.org/wiki/Levenshtein_distance
[3]: http://bevacqua.github.io/horsey
[4]: http://jsperf.com/fuzzysearch-regex/14