* import cultures feature

* remove debug messages

* code cleanup
This commit is contained in:
Mészáros Anna Veronika 2022-04-02 22:42:54 +02:00 committed by GitHub
parent 1384daf6f9
commit af62ff915c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 110 additions and 32 deletions

19
modules/io/formats.js Normal file
View file

@ -0,0 +1,19 @@
"use strict"
window.Formats = (function () {
async function csvParser (file, separator=",") {
const txt = await file.text();
const rows = txt.split("\n");
const headers = rows.shift().split(separator).map(x => x.toLowerCase());
const data = rows.filter(a => a.trim()!=="").map(r=>r.split(separator));
return {
headers,
data,
iterator: function* (sortf){
const dataset = sortf? this.data.sort(sortf):this.data;
for (const d of dataset)
yield Object.fromEntries(d.map((a, i) => [this.headers[i], a]));
}};
}
return {csvParser};
})();