@esmate/utils 1.0.5 → 1.0.8

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 CHANGED
@@ -3,23 +3,23 @@ export interface TimeZone {
3
3
  value: string;
4
4
  offset: string;
5
5
  }
6
- export declare function getTimeZoneList(locale?: string): TimeZone[];
6
+ export declare function getTimeZones(locale?: string): TimeZone[];
7
7
  export declare function getCurrentTimeZone(): string;
8
8
  interface Language {
9
9
  name: string;
10
10
  value: string;
11
11
  }
12
- export declare function getLanguageList(locale?: string): Language[];
12
+ export declare function getLanguages(locale?: string): Language[];
13
13
  export declare function getCurrentLanguage(): string;
14
14
  interface Country {
15
15
  name: string;
16
16
  value: string;
17
17
  }
18
- export declare function getCountryList(locale?: string): Country[];
18
+ export declare function getCountries(locale?: string): Country[];
19
19
  export declare function getCurrentCountry(): string;
20
20
  interface Currency {
21
21
  name: string;
22
22
  value: string;
23
23
  }
24
- export declare function getCurrencyList(locale?: string): Currency[];
24
+ export declare function getCurrencies(locale?: string): Currency[];
25
25
  export {};
package/dist/locale.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_iso_3166_1_0ebcf719__ from "iso-3166-1";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE_iso_639_1_39eb3c8b__ from "iso-639-1";
3
- function getTimeZoneList(locale = "en-US") {
3
+ function getTimeZones(locale = "en-US") {
4
4
  const timeZones = Intl.supportedValuesOf("timeZone");
5
5
  const getOffset = (timeZone)=>{
6
6
  const offset = new Intl.DateTimeFormat(locale, {
@@ -22,7 +22,7 @@ function getTimeZoneList(locale = "en-US") {
22
22
  function getCurrentTimeZone() {
23
23
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
24
24
  }
25
- function getLanguageList(locale = "en-US") {
25
+ function getLanguages(locale = "en-US") {
26
26
  const codes = __WEBPACK_EXTERNAL_MODULE_iso_639_1_39eb3c8b__["default"].getAllCodes().sort((a, b)=>a.localeCompare(b));
27
27
  return codes.map((code)=>{
28
28
  const name = new Intl.DisplayNames([
@@ -31,32 +31,35 @@ function getLanguageList(locale = "en-US") {
31
31
  type: "language"
32
32
  }).of(code);
33
33
  return {
34
- name: name || "",
34
+ name: name === code ? __WEBPACK_EXTERNAL_MODULE_iso_639_1_39eb3c8b__["default"].getName(code) : name,
35
35
  value: code
36
36
  };
37
- }).filter((lang)=>lang.name).sort((a, b)=>a.name.localeCompare(b.name));
37
+ }).sort((a, b)=>a.name.localeCompare(b.name));
38
38
  }
39
39
  function getCurrentLanguage() {
40
40
  return (navigator.language || "en-US").split("-")[0];
41
41
  }
42
- function getCountryList(locale = "en-US") {
43
- const codes = __WEBPACK_EXTERNAL_MODULE_iso_3166_1_0ebcf719__["default"].all().map((country)=>country.alpha2).sort((a, b)=>a.localeCompare(b));
44
- return codes.map((code)=>{
42
+ function getCountries(locale = "en-US") {
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)=>{
45
48
  const name = new Intl.DisplayNames([
46
49
  locale
47
50
  ], {
48
51
  type: "region"
49
- }).of(code);
52
+ }).of(country.code);
50
53
  return {
51
- name: name || "",
52
- value: code
54
+ name: name === country.code ? country.name : name,
55
+ value: country.code
53
56
  };
54
- }).filter((country)=>country.name).sort((a, b)=>a.name.localeCompare(b.name));
57
+ }).sort((a, b)=>a.name.localeCompare(b.name));
55
58
  }
56
59
  function getCurrentCountry() {
57
60
  return (navigator.language || "en-US").split("-")[1];
58
61
  }
59
- function getCurrencyList(locale = "en-US") {
62
+ function getCurrencies(locale = "en-US") {
60
63
  const codes = Intl.supportedValuesOf("currency");
61
64
  return codes.map((code)=>{
62
65
  const name = new Intl.DisplayNames([
@@ -71,4 +74,4 @@ function getCurrencyList(locale = "en-US") {
71
74
  };
72
75
  }).sort((a, b)=>a.name.localeCompare(b.name));
73
76
  }
74
- export { getCountryList, getCurrencyList, getCurrentCountry, getCurrentLanguage, getCurrentTimeZone, getLanguageList, getTimeZoneList };
77
+ export { getCountries, getCurrencies, getCurrentCountry, getCurrentLanguage, getCurrentTimeZone, getLanguages, getTimeZones };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@esmate/utils",
3
3
  "type": "module",
4
- "version": "1.0.5",
4
+ "version": "1.0.8",
5
5
  "description": "JavaScript/TypeScript utils, functions, and classes in one package.",
6
6
  "license": "MIT",
7
7
  "repository": {