(input: { head: string; tail: string[] }, patterns: Record<string, any>)
| 31 | } |
| 32 | |
| 33 | export function allStructured(input: { head: string; tail: string[] }, patterns: Record<string, any>) { |
| 34 | const sorted = pipe(patterns, Object.entries, sortBy([([key]) => key.length, "asc"], [([key]) => key, "asc"])) |
| 35 | let result = undefined |
| 36 | for (const [pattern, value] of sorted) { |
| 37 | const parts = pattern.split(/\s+/) |
| 38 | if (!match(input.head, parts[0])) continue |
| 39 | if (parts.length === 1 || matchSequence(input.tail, parts.slice(1))) { |
| 40 | result = value |
| 41 | continue |
| 42 | } |
| 43 | } |
| 44 | return result |
| 45 | } |
| 46 | |
| 47 | function matchSequence(items: string[], patterns: string[]): boolean { |
| 48 | if (patterns.length === 0) return true |
nothing calls this directly
no test coverage detected