(p: string)
| 137 | |
| 138 | /** Convert a glob (supporting **, *, ?) into an anchored RegExp. */ |
| 139 | export function globToRe(p: string): RegExp { |
| 140 | const esc = p |
| 141 | .replace(/[.+^${}()|[\]\\]/g, "\\$&") |
| 142 | .replace(/\*\*/g, "\u0000") |
| 143 | .replace(/\*/g, "[^/]*") |
| 144 | .replace(/\u0000/g, ".*") |
| 145 | .replace(/\?/g, "."); |
| 146 | return new RegExp(`^${esc}$`); |
| 147 | } |
| 148 | |
| 149 | /** Substring/subsequence fuzzy score (higher = better; 0 = no match). */ |
| 150 | export function fuzzyScore(text: string, query: string): number { |