Versie 1.0

This commit is contained in:
2026-08-09 19:03:26 +02:00
parent c70293405f
commit f3da7dfb8d
18 changed files with 877 additions and 3 deletions
+36
View File
@@ -0,0 +1,36 @@
module.exports = function parseCsv(input) {
const rows = [];
let row = [];
let field = "";
let quoted = false;
for (let index = 0; index < input.length; index += 1) {
const character = input[index];
const nextCharacter = input[index + 1];
if (character === '"' && quoted && nextCharacter === '"') {
field += '"';
index += 1;
} else if (character === '"') {
quoted = !quoted;
} else if (character === "," && !quoted) {
row.push(field);
field = "";
} else if ((character === "\n" || character === "\r") && !quoted) {
if (character === "\r" && nextCharacter === "\n") index += 1;
row.push(field);
if (row.some(value => value.trim() !== "")) rows.push(row);
row = [];
field = "";
} else {
field += character;
}
}
if (quoted) throw new Error("CSV bevat een niet afgesloten tekstveld.");
row.push(field);
if (row.some(value => value.trim() !== "")) rows.push(row);
return rows;
};