Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 4x 3x 3x 6x 6x 12x 12x | /* eslint-disable @typescript-eslint/no-explicit-any */
export const csvToJson = (csv: string, delimiter = ","): unknown => {
const titles = csv.slice(0, csv.indexOf("\n")).split(delimiter);
return csv
.slice(csv.indexOf("\n") + 1)
.split("\n")
.map((value) => {
const values = value.split(delimiter);
return titles.reduce((obj: any, title, index) => {
// eslint-disable-next-line security/detect-object-injection,no-param-reassign
obj[title] = values[index];
return obj;
}, {});
});
};
/* eslint-enable @typescript-eslint/no-explicit-any */
|