MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / fuzzyScore

Function fuzzyScore

src/ui/components/InputBox.tsx:23–38  ·  view source on GitHub ↗

Higher is better; -1 means no match. Prefers basename prefix > basename > path > subsequence.

(target: string, query: string)

Source from the content-addressed store, hash-verified

21
22/** Higher is better; -1 means no match. Prefers basename prefix > basename > path > subsequence. */
23function fuzzyScore(target: string, query: string): number {
24 if (!query) return 1
25 const t = target.toLowerCase()
26 const q = query.toLowerCase()
27 const base = (target.split("/").pop() ?? target).toLowerCase()
28 if (base.startsWith(q)) return 4000 - target.length
29 if (base.includes(q)) return 3000 - target.length
30 const idx = t.indexOf(q)
31 if (idx !== -1) return 2000 - idx - target.length
32 let qi = 0
33 for (let i = 0; i < t.length && qi < q.length; i++) {
34 if (t[i] === q[qi]) qi++
35 }
36 if (qi === q.length) return 1000 - target.length
37 return -1
38}
39
40/** The `@token` being typed at the cursor, if any. */
41function findAtToken(value: string, cursor: number): { query: string; start: number } | null {

Callers 1

InputBoxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected