* feat: model hub revamp UI * chore: model description - consistent markdown css * chore: add model versions dropdown * chore: integrate APIs - model sources * chore: update model display name * chore: lint fix * chore: page transition animation * feat: model search dropdown - deeplink * chore: bump cortex version * chore: add remote model sources * chore: model download state * chore: fix model metadata label * chore: polish model detail page markdown * test: fix test cases * chore: initialize default Hub model sources * chore: fix model stats * chore: clean up click outside and inside hooks * feat: change hub banner * chore: lint fix * chore: fix css long model id
24 lines
535 B
TypeScript
24 lines
535 B
TypeScript
/**
|
|
* Searches for a query in a list of data using a fuzzy search algorithm.
|
|
*/
|
|
export function fuzzySearch(needle: string, haystack: string) {
|
|
const hlen = haystack.length
|
|
const nlen = needle.length
|
|
if (nlen > hlen) {
|
|
return false
|
|
}
|
|
if (nlen === hlen) {
|
|
return needle === haystack
|
|
}
|
|
outer: for (let i = 0, j = 0; i < nlen; i++) {
|
|
const nch = needle.charCodeAt(i)
|
|
while (j < hlen) {
|
|
if (haystack.charCodeAt(j++) === nch) {
|
|
continue outer
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
return true
|
|
}
|