feat: swap-csv-columns fixed

This commit is contained in:
Chesterkxng
2025-04-01 15:40:19 +00:00
parent d56af77ed5
commit 477117cd8c
4 changed files with 70 additions and 69 deletions

View File

@@ -13,7 +13,7 @@ export function splitCsv(
let rows = input.split('\n').map((row) => row.split(','));
// Remove comments if deleteComment is true
if (deleteComment) {
if (deleteComment && commentCharacter) {
rows = rows.filter((row) => !row[0].trim().startsWith(commentCharacter));
}
@@ -24,3 +24,13 @@ export function splitCsv(
return rows;
}
/**
* get the headers from a CSV string .
* @param {string} input - The CSV input string.
* @returns {string[]} - The CSV header as a 1D array.
*/
export function getCsvHeaders(csvString: string): string[] {
const rows = csvString.split('\n').map((row) => row.split(','));
return rows.length > 0 ? rows[0].map((header) => header.trim()) : [];
}