(str: string)
| 42 | * @returns The string with trailing whitespace removed from each line |
| 43 | */ |
| 44 | export function stripTrailingWhitespace(str: string): string { |
| 45 | // Handle different line endings: CRLF, LF, CR |
| 46 | // Use a regex that matches line endings and captures them |
| 47 | const lines = str.split(/(\r\n|\n|\r)/) |
| 48 | |
| 49 | let result = '' |
| 50 | for (let i = 0; i < lines.length; i++) { |
| 51 | const part = lines[i] |
| 52 | if (part !== undefined) { |
| 53 | if (i % 2 === 0) { |
| 54 | // Even indices are line content |
| 55 | result += part.replace(/\s+$/, '') |
| 56 | } else { |
| 57 | // Odd indices are line endings |
| 58 | result += part |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return result |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Finds the actual string in the file content that matches the search string, |
no outgoing calls
no test coverage detected