mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 14:09:31 +02:00
fix: edge case (empty string in csv-rows-to-columns)
This commit is contained in:
@@ -17,12 +17,18 @@ export function csvRowsToColumns(
|
|||||||
customFiller: string,
|
customFiller: string,
|
||||||
commentCharacter: string
|
commentCharacter: string
|
||||||
): string {
|
): string {
|
||||||
|
if (!input) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
const rows = input
|
const rows = input
|
||||||
.split('\n')
|
? input
|
||||||
.map((row) => row.split(','))
|
.split('\n')
|
||||||
.filter(
|
.map((row) => row.split(','))
|
||||||
(row) => row.length > 0 && !row[0].trim().startsWith(commentCharacter)
|
.filter(
|
||||||
);
|
(row) => row.length > 0 && !row[0].trim().startsWith(commentCharacter)
|
||||||
|
)
|
||||||
|
: [];
|
||||||
const columnCount = Math.max(...rows.map((row) => row.length));
|
const columnCount = Math.max(...rows.map((row) => row.length));
|
||||||
for (let i = 0; i < rows.length; i++) {
|
for (let i = 0; i < rows.length; i++) {
|
||||||
for (let j = 0; j < columnCount; j++) {
|
for (let j = 0; j < columnCount; j++) {
|
||||||
|
Reference in New Issue
Block a user