Giter Site home page Giter Site logo

trifacta / fuzzy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kseth/fuzzy

0.0 7.0 1.0 3.49 MB

Filters a list based on a fuzzy string search

Home Page: mattyork.github.com/fuzzy

License: MIT License

Makefile 2.93% JavaScript 90.55% HTML 6.52%

fuzzy's Introduction

fuzzy

1k standalone fuzzy search / fuzzy filter a la Textmate and Sublime Text's command-T fuzzy file search. Node or browser.

Get it

Node:

$ npm install fuzzy
$ node
> var fuzzy = require('fuzzy');
> console.log(fuzzy)
{ test: [Function],
  match: [Function],
  filter: [Function] }

Browser:

<script src="/path/to/fuzzy.js"></script>
<script>
  console.log(fuzzy);
  // Object >
  //   filter: function (pattern, arr, opts) {
  //   match: function (pattern, string, opts) {
  //   test: function (pattern, string) {
</script>

Use it

Padawan: Simply filter an array of strings.

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

var list = ['baconing', 'narwhal', 'a mighty bear canoe'];
var options = { pre: '<', post: '>' };
var results = fuzzy.filter('bcn', list, options)
console.log(results);
// [
//   {string: '<b>a<c>o<n>ing'           , index: 0, score: 3, original: 'baconing'},
//   {string: 'a mighty <b>ear <c>a<n>oe', index: 2, score: 3, original: 'a mighty bear canoe'}
// ]

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

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);
// [ '<b>a<c>o<n>ing', 'a mighty <b>ear <c>a<n>oe' ]

Examples

Check out the html files in the examples directory

Documentation

Code is well documented and the unit tests cover all functionality

Contributing

Fork the repo!

git clone <your_fork>
cd fuzzy
npm install -d
make

Add unit tests for any new or changed functionality. Lint, test, and minify using make, then shoot me a pull request.

Release History

v0.1.0 - July 25, 2012

License

Copyright (c) 2015 Matt York Licensed under the MIT license.

TODO

  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: <b>od<a>ciou<s> ba<s>s. 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 <r><e>active r<i><c>e
  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!

fuzzy's People

Contributors

mattyork avatar swatinem avatar fasterthanlime avatar

Watchers

Jeffrey Heer avatar Seshadri Mahalingam avatar  avatar James Cloos avatar Zain Asgar avatar  avatar  avatar

Forkers

guptam

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.