@esmate/utils 1.0.4 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/locale.js +11 -10
- package/package.json +1 -1
package/dist/locale.js
CHANGED
|
@@ -30,30 +30,31 @@ function getLanguageList(locale = "en-US") {
|
|
|
30
30
|
], {
|
|
31
31
|
type: "language"
|
|
32
32
|
}).of(code);
|
|
33
|
-
if (void 0 === name) throw new Error(`Language name not found for code: ${code}`);
|
|
34
33
|
return {
|
|
35
|
-
name,
|
|
34
|
+
name: name === code ? __WEBPACK_EXTERNAL_MODULE_iso_639_1_39eb3c8b__["default"].getName(code) : name,
|
|
36
35
|
value: code
|
|
37
36
|
};
|
|
38
|
-
}).
|
|
37
|
+
}).sort((a, b)=>a.name.localeCompare(b.name));
|
|
39
38
|
}
|
|
40
39
|
function getCurrentLanguage() {
|
|
41
40
|
return (navigator.language || "en-US").split("-")[0];
|
|
42
41
|
}
|
|
43
42
|
function getCountryList(locale = "en-US") {
|
|
44
|
-
const
|
|
45
|
-
|
|
43
|
+
const countryList = __WEBPACK_EXTERNAL_MODULE_iso_3166_1_0ebcf719__["default"].all().map((country)=>({
|
|
44
|
+
name: country.country,
|
|
45
|
+
code: country.alpha2
|
|
46
|
+
}));
|
|
47
|
+
return countryList.map((country)=>{
|
|
46
48
|
const name = new Intl.DisplayNames([
|
|
47
49
|
locale
|
|
48
50
|
], {
|
|
49
51
|
type: "region"
|
|
50
|
-
}).of(code);
|
|
51
|
-
if (void 0 === name) throw new Error(`Country name not found for code: ${code}`);
|
|
52
|
+
}).of(country.code);
|
|
52
53
|
return {
|
|
53
|
-
name,
|
|
54
|
-
value: code
|
|
54
|
+
name: name === country.code ? country.name : name,
|
|
55
|
+
value: country.code
|
|
55
56
|
};
|
|
56
|
-
}).
|
|
57
|
+
}).sort((a, b)=>a.name.localeCompare(b.name));
|
|
57
58
|
}
|
|
58
59
|
function getCurrentCountry() {
|
|
59
60
|
return (navigator.language || "en-US").split("-")[1];
|