forked from openfoodfacts/hunger-games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-countries.js
29 lines (28 loc) · 885 Bytes
/
update-countries.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
const fs = require("fs");
const axios = require("axios");
axios("https://static.openfoodfacts.org/data/taxonomies/countries.json")
.then(({ data }) => {
fs.writeFile(
"./src/assets/countries.json",
JSON.stringify(
Object.entries(data)
.map(([key, value]) => ({
id: key,
label: value.name.en,
languageCode:
value.languages === undefined
? "en"
: value.languages.en === undefined
? undefined
: value.languages.en.split(",")[0],
countryCode:
value.country_code_2 === undefined
? undefined
: value.country_code_2.en,
}))
.sort((a, b) => a.label.localeCompare(b.label))
),
() => console.log("Countries updated")
);
})
.catch(console.error);