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