-
Notifications
You must be signed in to change notification settings - Fork 11
/
convert.js
42 lines (35 loc) · 1.03 KB
/
convert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const csv = require('csvtojson');
const fs = require('fs');
const FILE = "./euforestspecies.csv";
const CATALOGS = "./catalogs/"
async function init() {
let rows = await csv().fromFile(FILE);
build({
rows,
key: "COUNTRY",
fileName: "countries",
});
build({
rows,
key: "SPECIES NAME",
fileName: "species",
});
}
// function buildSpecies(rows) {
// let species_full = rows.map((item) => item["SPECIES NAME"]);
// let species = [...new Set(countries_full)];
// fs.writeFileSync(`${CATALOGS}species.json`, JSON.stringify(countries));
// }
// function buildCountries(rows) {
// let countries_full = rows.map((item) => item["COUNTRY"]);
// let countries = [...new Set(countries_full)];
// fs.writeFileSync(`${CATALOGS}countries.json`, JSON.stringify(countries));
// }
function build({
rows, key, fileName,
}) {
let full_collection = rows.map((item) => item[key]);
let collection = [...new Set(full_collection)];
fs.writeFileSync(`${CATALOGS}${fileName}.json`, JSON.stringify(collection));
}
init();