You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
662 B
29 lines
662 B
2 years ago
|
import spectrum from "csv-spectrum";
|
||
|
|
||
|
/*
|
||
|
* A naive CVS parser to start comparing with the existing neat-csv
|
||
|
* parser. This wrong for many CSV inputs, but you'll take this and
|
||
|
* work to make it behave as well as the neat-csv parser.
|
||
|
*/
|
||
|
const simple_parse = (raw_csv) => {
|
||
|
const rows = raw_csv.split("\n");
|
||
|
const result = [];
|
||
|
|
||
|
for(let row of rows) {
|
||
|
result.push(row.split(','));
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
|
||
|
spectrum(async (err, samples) => {
|
||
|
for(let sample of samples) {
|
||
|
const raw_csv = sample.csv.toString();
|
||
|
console.log("RAW CSV:\n", raw_csv);
|
||
|
|
||
|
const parsed = await simple_parse(raw_csv);
|
||
|
console.log("PARSED:\n", parsed);
|
||
|
}
|
||
|
});
|