Giter Site home page Giter Site logo

jkso / fuzzysort Goto Github PK

View Code? Open in Web Editor NEW

This project forked from farzher/fuzzysort

0.0 2.0 0.0 442 KB

Fast SublimeText-like fuzzy search for JavaScript.

Home Page: https://rawgit.com/farzher/fuzzysort/master/test.html

JavaScript 99.73% HTML 0.27%

fuzzysort's Introduction

Fast SublimeText-like fuzzy search for JavaScript.

Sublime's fuzzy search is... sublime. I wish everything used it. So here's an open source js version.

https://rawgit.com/farzher/fuzzysort/master/test.html

Installation Node

npm i fuzzysort
node
> require('fuzzysort').single('t', 'test')
{ score: 3, highlighted: '<b>t</b>est' }

Installation Browser

<script src="https://rawgit.com/farzher/fuzzysort/master/fuzzysort.js"></script>
<script>
console.log(fuzzysort.single('t', 'test'))
</script>

Usage

fuzzysort.single(search, target)

fuzzysort.single('query', 'some string that contains my query.')
// {score: 59, highlighted: "some string that contains my <b>query</b>."}

fuzzysort.single('query', 'irrelevant string') // null

// exact match returns a score of 0. lower score is better
fuzzysort.single('query', 'query') // {score: 0, highlighted: "<b>query</b>"}

fuzzysort.go(search, targets)

fuzzysort.go('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
// [{score: 18, highlighted: "<b>M</b>esh<b>R</b>enderer.cpp"}
// ,{score: 6009, highlighted: "<b>M</b>onito<b>r</b>.cpp"}]

fuzzysort.goAsync(search, targets)

let promise = fuzzysort.goAsync('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
promise.then(results => console.log(results))
if(invalidated) promise.cancel()
Options
  • fuzzysort.noMatchLimit = 100 If there's no match for a span this long, give up (improves performance of long search targets)
  • fuzzysort.highlightMatches = true Turn this off if you don't care about highlighted (improves performance)
  • fuzzysort.highlightOpen = '<b>'
  • fuzzysort.highlightClose = '</b>'
  • fuzzysort.threshold = null Don't return matches worse than this (improves performance) (irrelevant for single)
  • fuzzysort.limit = null Don't return more results than this (improves performance if highlightMatches is on) (irrelevant for single)

fuzzysort's People

Contributors

farzher avatar

Watchers

James Cloos avatar pylonkin avatar

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.