| 20 | * completely empty lines from the beginning and end. |
| 21 | */ |
| 22 | export function stripEmptyLines(content: string): string { |
| 23 | const lines = content.split('\n') |
| 24 | |
| 25 | // Find the first non-empty line |
| 26 | let startIndex = 0 |
| 27 | while (startIndex < lines.length && lines[startIndex]?.trim() === '') { |
| 28 | startIndex++ |
| 29 | } |
| 30 | |
| 31 | // Find the last non-empty line |
| 32 | let endIndex = lines.length - 1 |
| 33 | while (endIndex >= 0 && lines[endIndex]?.trim() === '') { |
| 34 | endIndex-- |
| 35 | } |
| 36 | |
| 37 | // If all lines are empty, return empty string |
| 38 | if (startIndex > endIndex) { |
| 39 | return '' |
| 40 | } |
| 41 | |
| 42 | // Return the slice with non-empty lines |
| 43 | return lines.slice(startIndex, endIndex + 1).join('\n') |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Check if content is a base64 encoded image data URL |