mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fix: uploadCulturesData
This commit is contained in:
parent
4e884b10ee
commit
14ac83e6f5
5 changed files with 32 additions and 41 deletions
|
|
@ -1,24 +0,0 @@
|
|||
"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};
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue