(text: string)
| 4 | } |
| 5 | |
| 6 | export const formatReportSections = (text: string): FormattedSection[] => { |
| 7 | if (!text) return []; |
| 8 | |
| 9 | // Split the report by lines first |
| 10 | const lines = text.split("\n"); |
| 11 | const sections: FormattedSection[] = []; |
| 12 | let currentSection: FormattedSection | null = null; |
| 13 | |
| 14 | // Process each line to organize into sections |
| 15 | lines.forEach((line) => { |
| 16 | // Check if this is a section title (starts with ">>") |
| 17 | if (line.trim().startsWith(">>")) { |
| 18 | // If we have a current section, add it to our sections array |
| 19 | if (currentSection) { |
| 20 | sections.push(currentSection); |
| 21 | } |
| 22 | // Start a new section with this title |
| 23 | currentSection = { |
| 24 | title: line.trim().substring(2).trim(), // Remove ">>" prefix and trim |
| 25 | content: [], |
| 26 | }; |
| 27 | } |
| 28 | // Otherwise this is content for the current section |
| 29 | else if (currentSection) { |
| 30 | currentSection.content.push(line); |
| 31 | } |
| 32 | // If we encounter content before any title, create a default section |
| 33 | else { |
| 34 | currentSection = { |
| 35 | title: "", |
| 36 | content: [line], |
| 37 | }; |
| 38 | } |
| 39 | }); |
| 40 | |
| 41 | // Add the last section if it exists |
| 42 | if (currentSection) { |
| 43 | sections.push(currentSection); |
| 44 | } |
| 45 | |
| 46 | return sections; |
| 47 | }; |
no outgoing calls
no test coverage detected