( entries: WireEntryPoints | null, query: string, limit: number )
| 355 | * being predictable. |
| 356 | */ |
| 357 | export function matchEntries( |
| 358 | entries: WireEntryPoints | null, |
| 359 | query: string, |
| 360 | limit: number |
| 361 | ): EntryMatch[] { |
| 362 | const needle = query.trim().toLowerCase(); |
| 363 | if (!entries || needle === '') return []; |
| 364 | |
| 365 | const pools: Array<[EntryMatch['origin'], EntryRow[]]> = [ |
| 366 | ['route', entries.routes.routed ? entries.routes.items.items.map(routeRow) : []], |
| 367 | ['file', entries.files.items.map(fileRow)], |
| 368 | ['test', entries.tests.items.map(testRow)], |
| 369 | ['hub', entries.hubs.items.map(hubRow)], |
| 370 | ]; |
| 371 | |
| 372 | const matches: EntryMatch[] = []; |
| 373 | for (const [origin, rows] of pools) { |
| 374 | for (const row of rows) { |
| 375 | if (matches.length >= limit) return matches; |
| 376 | const haystack = `${row.method ?? ''} ${row.name} ${row.meta} ${row.title}`.toLowerCase(); |
| 377 | if (haystack.includes(needle)) matches.push({ row, origin }); |
| 378 | } |
| 379 | } |
| 380 | return matches; |
| 381 | } |
| 382 | |
| 383 | /** The location column for a palette entry row — where it came from. */ |
| 384 | export function originLabel(origin: EntryMatch['origin']): string { |
no test coverage detected