28 lines
822 B
TypeScript
28 lines
822 B
TypeScript
import { individus } from "./individus.ts";
|
|
|
|
function download(filename: string, content:any, type:string) {
|
|
const blob = new Blob([content], { type });
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = filename;
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
}
|
|
|
|
document.getElementById("download-json")!.addEventListener("click", () => {
|
|
console.log(individus);
|
|
const json = JSON.stringify(individus, null, 2);
|
|
download("individus.json", json, "application/json");
|
|
});
|
|
|
|
document.getElementById("download-csv")!.addEventListener("click", () => {
|
|
const headers = Object.keys(individus[0]);
|
|
const csv = [
|
|
headers.join(";"),
|
|
...individus.map(i => headers.map(h => i[h]).join(";"))
|
|
].join("\n");
|
|
|
|
download("individus.csv", csv, "text/csv");
|
|
});
|