mirror of
https://github.com/owncast/owncast.git
synced 2024-11-23 21:28:29 +03:00
dab7914eab
* Commit updated Javascript packages * Bump preact from 10.5.4 to 10.5.5 in /build/javascript (#265) * Trying a new github workflow to install javascript packages * Bump tailwindcss from 1.9.2 to 1.9.4 in /build/javascript (#266) Bumps [tailwindcss](https://github.com/tailwindlabs/tailwindcss) from 1.9.2 to 1.9.4. - [Release notes](https://github.com/tailwindlabs/tailwindcss/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/master/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v1.9.2...v1.9.4) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Commit updated Javascript packages * Bump preact from 10.5.4 to 10.5.5 in /build/javascript Bumps [preact](https://github.com/preactjs/preact) from 10.5.4 to 10.5.5. - [Release notes](https://github.com/preactjs/preact/releases) - [Commits](https://github.com/preactjs/preact/compare/10.5.4...10.5.5) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Owncast <owncast@owncast.online> * Bump @justinribeiro/lite-youtube in /build/javascript Bumps [@justinribeiro/lite-youtube](https://github.com/justinribeiro/lite-youtube) from 0.9.0 to 0.9.1. - [Release notes](https://github.com/justinribeiro/lite-youtube/releases) - [Commits](https://github.com/justinribeiro/lite-youtube/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Owncast <owncast@owncast.online> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com> |
||
---|---|---|
.. | ||
fuzzysort.js | ||
index.d.ts | ||
LICENSE | ||
package.json | ||
README.md |
fuzzysort
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.
Demo
https://rawgit.com/farzher/fuzzysort/master/test.html
Installation Node
npm install fuzzysort
const fuzzysort = require('fuzzysort')
Installation Browser
<script src="https://rawgit.com/farzher/fuzzysort/master/fuzzysort.js"></script>
Most Common Usage
fuzzysort.go(search, targets, options=null)
const mystuff = [{file:'Monitor.cpp'}, {file:'MeshRenderer.cpp'}]
const results = fuzzysort.go('mr', mystuff, {key:'file'})
// [{score:-18, obj:{file:'MeshRenderer.cpp'}}, {score:-6009, obj:{file:'Monitor.cpp'}}]
Usage
fuzzysort.go(search, targets, options=null)
const results = fuzzysort.go('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
// [{score: -18, target: "MeshRenderer.cpp"}, {score: -6009, target: "Monitor.cpp"}]
fuzzysort.goAsync(search, targets, options=null)
let promise = fuzzysort.goAsync('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
promise.then(results => console.log(results))
if(invalidated) promise.cancel()
Options
fuzzysort.go(search, targets, {
threshold: -Infinity, // Don't return matches worse than this (higher is faster)
limit: Infinity, // Don't return more results than this (lower is faster)
allowTypo: true, // Allwos a snigle transpoes (false is faster)
key: null, // For when targets are objects (see its example usage)
keys: null, // For when targets are objects (see its example usage)
scoreFn: null, // For use with `keys` (see its example usage)
})
fuzzysort.highlight(result, open='<b>', close='</b>')
fuzzysort.highlight(fuzzysort.single('tt', 'test'), '*', '*') // *t*es*t*
What is a result
const result = fuzzysort.single('query', 'some string that contains my query.')
// exact match returns a score of 0. lower is worse
result.score // -59
result.indexes // [29, 30, 31, 32, 33]
result.target // some string that contains my query.
result.obj // reference to your original obj when using options.key
fuzzysort.highlight(result, '<b>', '</b>') // some string that contains my <b>query</b>.
How To Go Fast · Performance Tips
let targets = [{file:'Monitor.cpp'}, {file:'MeshRenderer.cpp'}]
// filter out targets that you don't need to search! especially long ones!
targets = targets.filter(t => t.file.length < 1000)
// if your targets don't change often, provide prepared targets instead of raw strings!
targets.forEach(t => t.filePrepared = fuzzysort.prepare(t.file))
// don't use options.key if you don't need a reference to your original obj
targets = targets.map(t => t.filePrepared)
const options = {
limit: 100, // don't return more results than you need!
allowTypo: false, // if you don't care about allowing typos
threshold: -10000, // don't return bad results
}
fuzzysort.go('gotta', targets, options)
fuzzysort.go('go', targets, options)
fuzzysort.go('fast', targets, options)
Advanced Usage
Search a list of objects, by multiple fields, with custom weights.
let objects = [{title:'Favorite Color', desc:'Chrome'}, {title:'Google Chrome', desc:'Launch Chrome'}]
let results = fuzzysort.go('chr', objects, {
keys: ['title', 'desc'],
// Create a custom combined score to sort by. -100 to the desc score makes it a worse match
scoreFn(a) => Math.max(a[0]?a[0].score:-1000, a[1]?a[1].score-100:-1000)
})
var bestResult = results[0]
// When using multiple `keys`, results are different. They're indexable to get each normal result
fuzzysort.highlight(bestResult[0]) // 'Google <b>Chr</b>ome'
fuzzysort.highlight(bestResult[1]) // 'Launch <b>Chr</b>ome'
bestResult.obj.title // 'Google Chrome'
Multiple instances, each with different default options.
const strictsort = fuzzysort.new({threshold: -999})
Changelog
v1.1.0
- Added
allowTypo
as an option
v1.0.0
- Inverted scores; they're now negative instead of positive, so that higher scores are better
- Added ability to search objects by
key
/keys
with custom weights - Removed the option to automatically highlight and exposed
fuzzysort.highlight
- Removed all options from
fuzzysort
and moved them intofuzzysort.go
optional params
v0.x.x
- init