* Parse a key = value line. Returns null if the line doesn't contain a valid key.
(line: string)
| 76 | * Parse a key = value line. Returns null if the line doesn't contain a valid key. |
| 77 | */ |
| 78 | function parseKeyValue(line: string): { key: string; value: string } | null { |
| 79 | // Read key: alphanumeric + hyphen, starting with alpha |
| 80 | let i = 0 |
| 81 | while (i < line.length && isKeyChar(line[i]!)) { |
| 82 | i++ |
| 83 | } |
| 84 | if (i === 0) { |
| 85 | return null |
| 86 | } |
| 87 | const key = line.slice(0, i) |
| 88 | |
| 89 | // Skip whitespace |
| 90 | while (i < line.length && (line[i] === ' ' || line[i] === '\t')) { |
| 91 | i++ |
| 92 | } |
| 93 | |
| 94 | // Must have '=' |
| 95 | if (i >= line.length || line[i] !== '=') { |
| 96 | // Boolean key with no value — not relevant for our use cases |
| 97 | return null |
| 98 | } |
| 99 | i++ // skip '=' |
| 100 | |
| 101 | // Skip whitespace after '=' |
| 102 | while (i < line.length && (line[i] === ' ' || line[i] === '\t')) { |
| 103 | i++ |
| 104 | } |
| 105 | |
| 106 | const value = parseValue(line, i) |
| 107 | return { key, value } |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Parse a config value starting at position i. |
no test coverage detected