(content: string, aggressive: boolean = false)
| 175 | * @returns The content with line numbers removed |
| 176 | */ |
| 177 | export function stripLineNumbers(content: string, aggressive: boolean = false): string { |
| 178 | // Split into lines to handle each line individually |
| 179 | const lines = content.split(/\r?\n/) |
| 180 | |
| 181 | // Process each line |
| 182 | const processedLines = lines.map((line) => { |
| 183 | // Match line number pattern and capture everything after the pipe |
| 184 | const match = aggressive ? line.match(/^\s*(?:\d+\s)?\|\s(.*)$/) : line.match(/^\s*\d+\s+\|(?!\|)\s?(.*)$/) |
| 185 | return match ? match[1] : line |
| 186 | }) |
| 187 | |
| 188 | // Join back with original line endings (carriage return (\r) + line feed (\n) or just line feed (\n)) |
| 189 | const lineEnding = content.includes("\r\n") ? "\r\n" : "\n" |
| 190 | let result = processedLines.join(lineEnding) |
| 191 | |
| 192 | // Preserve trailing newline if present in original content |
| 193 | if (content.endsWith(lineEnding)) { |
| 194 | if (!result.endsWith(lineEnding)) { |
| 195 | result += lineEnding |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | return result |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Truncates multi-line output while preserving context from both the beginning and end. |
no outgoing calls
no test coverage detected