JSPM

  • Created
  • Published
  • Downloads 1131460
  • Score
    100M100P100Q187180F
  • License ISC

Package Exports

  • fuzzysort

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fuzzysort) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fuzzysort

Fast SublimeText-like fuzzy search for JavaScript.

Demo

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

Installation Node

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

Installation Browser

<script src="fuzzysort.js"></script>

Usage

fuzzysort.single(search, target)

fuzzysort.single('query', 'some string that contains my query.')
// {score: 0.059, 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: 0.018, highlighted: "<b>M</b>esh<b>R</b>enderer.cpp"}
// ,{score: 6.009, 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
  • fuzzysort.highlightMatches = true Turn this off if you don't care about highlighted
  • fuzzysort.highlightOpen = '<b>'
  • fuzzysort.highlightClose = '</b>'
  • fuzzysort.limit = null Don't return more results than this (improve performance by not highlighting everything)