@esmate/utils 1.0.3 → 1.0.5
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.d.ts +3 -0
- package/dist/locale.js +14 -7
- package/package.json +1 -1
package/dist/locale.d.ts
CHANGED
|
@@ -4,16 +4,19 @@ export interface TimeZone {
|
|
|
4
4
|
offset: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function getTimeZoneList(locale?: string): TimeZone[];
|
|
7
|
+
export declare function getCurrentTimeZone(): string;
|
|
7
8
|
interface Language {
|
|
8
9
|
name: string;
|
|
9
10
|
value: string;
|
|
10
11
|
}
|
|
11
12
|
export declare function getLanguageList(locale?: string): Language[];
|
|
13
|
+
export declare function getCurrentLanguage(): string;
|
|
12
14
|
interface Country {
|
|
13
15
|
name: string;
|
|
14
16
|
value: string;
|
|
15
17
|
}
|
|
16
18
|
export declare function getCountryList(locale?: string): Country[];
|
|
19
|
+
export declare function getCurrentCountry(): string;
|
|
17
20
|
interface Currency {
|
|
18
21
|
name: string;
|
|
19
22
|
value: string;
|
package/dist/locale.js
CHANGED
|
@@ -19,6 +19,9 @@ function getTimeZoneList(locale = "en-US") {
|
|
|
19
19
|
};
|
|
20
20
|
}).sort((a, b)=>a.offset.localeCompare(b.offset) || a.name.localeCompare(b.name));
|
|
21
21
|
}
|
|
22
|
+
function getCurrentTimeZone() {
|
|
23
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
24
|
+
}
|
|
22
25
|
function getLanguageList(locale = "en-US") {
|
|
23
26
|
const codes = __WEBPACK_EXTERNAL_MODULE_iso_639_1_39eb3c8b__["default"].getAllCodes().sort((a, b)=>a.localeCompare(b));
|
|
24
27
|
return codes.map((code)=>{
|
|
@@ -27,12 +30,14 @@ function getLanguageList(locale = "en-US") {
|
|
|
27
30
|
], {
|
|
28
31
|
type: "language"
|
|
29
32
|
}).of(code);
|
|
30
|
-
if (void 0 === name) throw new Error(`Language name not found for code: ${code}`);
|
|
31
33
|
return {
|
|
32
|
-
name,
|
|
34
|
+
name: name || "",
|
|
33
35
|
value: code
|
|
34
36
|
};
|
|
35
|
-
}).sort((a, b)=>a.name.localeCompare(b.name));
|
|
37
|
+
}).filter((lang)=>lang.name).sort((a, b)=>a.name.localeCompare(b.name));
|
|
38
|
+
}
|
|
39
|
+
function getCurrentLanguage() {
|
|
40
|
+
return (navigator.language || "en-US").split("-")[0];
|
|
36
41
|
}
|
|
37
42
|
function getCountryList(locale = "en-US") {
|
|
38
43
|
const codes = __WEBPACK_EXTERNAL_MODULE_iso_3166_1_0ebcf719__["default"].all().map((country)=>country.alpha2).sort((a, b)=>a.localeCompare(b));
|
|
@@ -42,12 +47,14 @@ function getCountryList(locale = "en-US") {
|
|
|
42
47
|
], {
|
|
43
48
|
type: "region"
|
|
44
49
|
}).of(code);
|
|
45
|
-
if (void 0 === name) throw new Error(`Country name not found for code: ${code}`);
|
|
46
50
|
return {
|
|
47
|
-
name,
|
|
51
|
+
name: name || "",
|
|
48
52
|
value: code
|
|
49
53
|
};
|
|
50
|
-
}).sort((a, b)=>a.name.localeCompare(b.name));
|
|
54
|
+
}).filter((country)=>country.name).sort((a, b)=>a.name.localeCompare(b.name));
|
|
55
|
+
}
|
|
56
|
+
function getCurrentCountry() {
|
|
57
|
+
return (navigator.language || "en-US").split("-")[1];
|
|
51
58
|
}
|
|
52
59
|
function getCurrencyList(locale = "en-US") {
|
|
53
60
|
const codes = Intl.supportedValuesOf("currency");
|
|
@@ -64,4 +71,4 @@ function getCurrencyList(locale = "en-US") {
|
|
|
64
71
|
};
|
|
65
72
|
}).sort((a, b)=>a.name.localeCompare(b.name));
|
|
66
73
|
}
|
|
67
|
-
export { getCountryList, getCurrencyList, getLanguageList, getTimeZoneList };
|
|
74
|
+
export { getCountryList, getCurrencyList, getCurrentCountry, getCurrentLanguage, getCurrentTimeZone, getLanguageList, getTimeZoneList };
|