@ztimson/utils 0.23.17 → 0.23.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +7 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +7 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -684,6 +684,7 @@ function validateEmail(email) {
|
|
|
684
684
|
return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(email);
|
|
685
685
|
}
|
|
686
686
|
function fromCsv(csv, hasHeaders = true) {
|
|
687
|
+
var _a;
|
|
687
688
|
function parseLine(line) {
|
|
688
689
|
const columns = [];
|
|
689
690
|
let current = "", inQuotes2 = false;
|
|
@@ -696,25 +697,25 @@ function fromCsv(csv, hasHeaders = true) {
|
|
|
696
697
|
i++;
|
|
697
698
|
} else inQuotes2 = !inQuotes2;
|
|
698
699
|
} else if (char === "," && !inQuotes2) {
|
|
699
|
-
columns.push(current);
|
|
700
|
+
columns.push(current.trim());
|
|
700
701
|
current = "";
|
|
701
702
|
} else current += char;
|
|
702
703
|
}
|
|
703
|
-
columns.push(current);
|
|
704
|
+
columns.push(current.trim());
|
|
704
705
|
return columns.map((col) => col.replace(/^"|"$/g, "").replace(/""/g, '"'));
|
|
705
706
|
}
|
|
706
707
|
const rows2 = [];
|
|
707
708
|
let currentRow = "", inQuotes = false;
|
|
708
|
-
for (const char of csv) {
|
|
709
|
+
for (const char of csv.replace(/\r\n/g, "\n")) {
|
|
709
710
|
if (char === '"') inQuotes = !inQuotes;
|
|
710
711
|
if (char === "\n" && !inQuotes) {
|
|
711
|
-
rows2.push(currentRow);
|
|
712
|
+
rows2.push(currentRow.trim());
|
|
712
713
|
currentRow = "";
|
|
713
714
|
} else currentRow += char;
|
|
714
715
|
}
|
|
715
|
-
if (currentRow) rows2.push(currentRow);
|
|
716
|
+
if (currentRow) rows2.push(currentRow.trim());
|
|
716
717
|
let headers = hasHeaders ? rows2.splice(0, 1)[0] : null;
|
|
717
|
-
if (headers) headers = headers.match(/(?:[^,"']+|"(?:[^"]|"")*"|'(?:[^']|'')*')+/g);
|
|
718
|
+
if (headers) headers = (_a = headers.match(/(?:[^,"']+|"(?:[^"]|"")*"|'(?:[^']|'')*')+/g)) == null ? void 0 : _a.map((h) => h.trim());
|
|
718
719
|
return rows2.map((r2) => {
|
|
719
720
|
const props = parseLine(r2);
|
|
720
721
|
const h = headers || Array(props.length).fill(null).map((_, i) => {
|