(partialArgs: string)
| 151 | * nothing useful is found. |
| 152 | */ |
| 153 | export function extractTarget(partialArgs: string): string | null { |
| 154 | if (!partialArgs) return null; |
| 155 | for (const k of TARGET_KEYS) { |
| 156 | // Closed string value first. |
| 157 | const closed = new RegExp(`"${k}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"`).exec(partialArgs); |
| 158 | if (closed && closed[1] != null) return unescapeJson(closed[1]); |
| 159 | } |
| 160 | for (const k of TARGET_KEYS) { |
| 161 | // Unterminated value (stream cut mid-string) — capture to end. |
| 162 | const open = new RegExp(`"${k}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)$`).exec(partialArgs); |
| 163 | if (open && open[1] != null && open[1].length > 0) return unescapeJson(open[1]); |
| 164 | } |
| 165 | return null; |
| 166 | } |
| 167 | |
| 168 | function unescapeJson(s: string): string { |
| 169 | return s.replace(/\\n/g, ' ').replace(/\\t/g, ' ').replace(/\\"/g, '"').replace(/\\\\/g, '\\'); |
no test coverage detected