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
npm i fuzzysort
node
> require('fuzzysort').single('t', 'test')
{ score: 3, highlighted: '<b>t</b>est' }
<script src="fuzzysort.js"></script>
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('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"}]
let promise = fuzzysort.goAsync('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
promise.then(results => console.log(results))
if(invalidated) promise.cancel()
fuzzysort.noMatchLimit = 100
If there's no match for a span this long, give upfuzzysort.highlightMatches = true
Turn this off if you don't care abouthighlighted
fuzzysort.highlightOpen = '<b>'
fuzzysort.highlightClose = '</b>'
fuzzysort.limit = null
Don't return more results than this (improve performance by not highlighting everything)