style uploadCulturesData, fix removed issue

This commit is contained in:
Azgaar 2022-04-09 20:18:25 +05:00
parent d18bb87ddf
commit 1bec723d4f
2 changed files with 42 additions and 37 deletions

View file

@ -1,19 +1,24 @@
"use strict"
"use strict";
window.Formats = (function () {
async function csvParser (file, separator=",") {
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));
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]));
}};
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};
})();