-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (35 loc) · 1.06 KB
/
index.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
import countryList from "./data.json";
// 准备数据结构
const codeToCountry = {};
const nameToCountry = {};
const shortToCountry = {};
const enToCountry = {};
const groupEnToCountry = {};
const groupCnToCountry = [];
const countries = [];
countryList.forEach((obj) => {
const country = {
short: obj.short,
name: obj.name,
en: obj.en,
code: obj.code,
groupEn: obj.groupEn,
groupCn: obj.groupCn,
};
codeToCountry[obj.code] = country;
nameToCountry[obj.name] = country;
shortToCountry[obj.short] = country;
enToCountry[obj.en] = country;
groupEnToCountry[obj.groupEn] = country;
groupCnToCountry[obj.groupCn] = country;
countries.push(country);
});
export default {
getCountryByCode: (code) => codeToCountry[code],
getCountryByName: (name) => nameToCountry[name],
getCountries: () => countries,
getCountriesByShortName: (short) => shortToCountry[short],
getEnToCountry: (en) => enToCountry[en],
getGroupEnToCountry: (groupEn) => groupEnToCountry[groupEn],
getGroupCnToCountry: (groupCn) => groupCnToCountry[groupCn],
};