This repository was archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
72 lines (58 loc) · 2.06 KB
/
app.js
File metadata and controls
72 lines (58 loc) · 2.06 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const fs = require("fs");
const arrays = require("./arrays");
const files = {
currency: require("./countries-complete.json"),
langDateFormat: require("./country-lang-dateformat.json"),
allCountries: require("./countries-all.json"),
twelveHours: arrays.twelveHours,
decimalPoints: arrays.decimalPoint,
eu: arrays.eu,
businessIdNames: arrays.businessIdNames
};
const countriesAll = JSON.parse(JSON.stringify(files.allCountries));
const countriesCurrencies = JSON.parse(JSON.stringify(files.currency));
const countriesLangDate = JSON.parse(JSON.stringify(files.langDateFormat));
const mergeArr = [];
// merge the same countryCode
countriesAll.forEach(country => {
const id = country.countryCode;
const result = {
...country
};
// EU
const isEu = files.eu.includes(id);
if (isEu) {
result.eu = true;
}
// Currency
const currencyObject = countriesCurrencies[id];
result.currency = currencyObject ? currencyObject.currency : 'USD';
// DateFormat
const dateObject = countriesLangDate.find(
x => x.countryCode === id
);
result.dateFormat = dateObject ? dateObject.dateFormat : 'MM/DD/YYYY';
// Language
const langObject = countriesLangDate.find(
x => x.countryCode === id
);
result.langCode = langObject ? langObject.langCode : 'en';
// DistanceFormat
const distanceObject = countriesLangDate.find(
x => x.countryCode === id
);
result.distanceFormat = distanceObject && distanceObject.distance === 'miles' ? 'mi' : 'km';
// TimeFormat
const isTwelve = files.twelveHours.includes(id);
result.timeFormat = isTwelve ? "h:mma" : "HH:mm";
// NumberFormat
const isDecimal = files.decimalPoints.includes(id);
result.numberFormat = isDecimal ? "comma" : "dot";
// BusinessIdName
const idObject = files.businessIdNames.find(
x => x.id === id
);
result.businessIdName = idObject ? idObject.name : 'Business ID';
mergeArr.push(result);
});
fs.writeFileSync("./countries.json", JSON.stringify(mergeArr));