* Processes the content of a CSV file and returns the processed content. * * The processed content is a string where each row is prepended with the header row. * * @param csvContent - The content of the CSV file as a string. * @returns The processed content of the CSV file.
(csvContent: string)
| 147 | * @returns The processed content of the CSV file. |
| 148 | */ |
| 149 | function processCSV(csvContent: string): string { |
| 150 | // Split the content into rows |
| 151 | const rows = csvContent.split('\n'); |
| 152 | |
| 153 | // Extract the header row |
| 154 | const header = rows[0].replace('\r', ''); |
| 155 | |
| 156 | // Process each data row and join them into a single string |
| 157 | const processedContent = rows |
| 158 | .slice(1) |
| 159 | .map(row => { |
| 160 | // Skip empty rows and rows with only commas |
| 161 | if (row.trim() === '' || /^[,]+$/.test(row.trim())) { |
| 162 | return ''; |
| 163 | } |
| 164 | return header + '\n' + row; |
| 165 | }) |
| 166 | .join('\n\n'); |
| 167 | |
| 168 | return processedContent; |
| 169 | } |
no outgoing calls
no test coverage detected