small, standalone fuzzy search / fuzzy filter. browser or node
npm install fuzzy1k standalone fuzzy search / fuzzy filter a la Sublime Text's command-p fuzzy file search. Works in both node and browser.

Try it yourself: Disney Character Search Example
Node:
``bash`
$ npm install --save fuzzy
$ node
> var fuzzy = require('fuzzy');
> console.log(fuzzy)
{ test: [Function],
match: [Function],
filter: [Function] }
Browser:
`html`
Padawan: Simply filter an array of strings.
`javascript`
var list = ['baconing', 'narwhal', 'a mighty bear canoe'];
var results = fuzzy.filter('bcn', list)
var matches = results.map(function(el) { return el.string; });
console.log(matches);
// [ 'baconing', 'a mighty bear canoe' ]
Jedi: Wrap matching characters in each string
`javascript`
var list = ['baconing', 'narwhal', 'a mighty bear canoe'];
var options = { pre: '<', post: '>' };
var results = fuzzy.filter('bcn', list, options)
console.log(results);
// [
// {string: 'a
// {string: 'a mighty ear
// ]
Jedi Master: sometimes the array you give is not an array of strings. You can
pass in a function that creates the string to match against from each element
in the given array
`javascript`
var list = [
{rompalu: 'baconing', zibbity: 'simba'}
, {rompalu: 'narwhal' , zibbity: 'mufasa'}
, {rompalu: 'a mighty bear canoe', zibbity: 'saddam hussein'}
];
var options = {
pre: '<'
, post: '>'
, extract: function(el) { return el.rompalu; }
};
var results = fuzzy.filter('bcn', list, options);
var matches = results.map(function(el) { return el.string; });
console.log(matches);
// [ 'a
Try the examples live:
- disney
- wikipedia
git clone
cd fuzzy
npm install
make
Add unit tests for any new or changed functionality. Lint, test, and minify using make, then shoot me a pull request.
* Initial Release
v0.1.1 - September 19, 2015
* Fix broken links in package.json
* Fix examples
v0.1.2 - September 25, 2016
* Exact matches get the highest score. #15
* Add TypeScript typings #21
* Better error handling for invalid input #13
* Smaller bower install footprint #22
v0.1.3 - October 1, 2016
* Fix blocking bug in React Native #27
1. Search improvement: behave a bit more like sublime text by getting
the BEST match in a given string, not just the first. For example,
searching for 'bass' in 'bodacious bass' should match against 'bass',
but it currently matches like so: odciou bas. There is
a test already written, just need to implement it. Naive O(n^2) worst
case: find every match in the string, then select the highest scoring
match. Should benchmark this against current implementation once implemented
Also, "reactive rice" would be
2. Search feature: Work on multiple strings in a match. For example, be able
to match against 'stth' against an object { folder: 'stuff', file: 'thing' }
3. Async batch updates so the UI doesn't block for huge sets. Or maybe Web Workers?
4. Performance performance performance!