@formatjs/intl-enumerator 1.1.1 → 1.1.2

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.
Files changed (131) hide show
  1. package/BUILD +136 -0
  2. package/CHANGELOG.md +25 -0
  3. package/LICENSE.md +0 -0
  4. package/README.md +0 -0
  5. package/index.ts +9 -0
  6. package/package.json +5 -2
  7. package/polyfill-force.ts +8 -0
  8. package/polyfill.ts +11 -0
  9. package/scripts/calendars.ts +21 -0
  10. package/scripts/collations.ts +21 -0
  11. package/scripts/currencies.ts +21 -0
  12. package/scripts/timezones.ts +22 -0
  13. package/scripts/units.ts +23 -0
  14. package/should-polyfill.ts +3 -0
  15. package/src/calendars.generated.ts +5 -0
  16. package/src/collations.generated.ts +5 -0
  17. package/src/currencies.generated.ts +5 -0
  18. package/src/get-supported-calendars.ts +17 -0
  19. package/src/get-supported-collations.ts +16 -0
  20. package/src/get-supported-currencies.ts +48 -0
  21. package/src/get-supported-numbering-systems.ts +21 -0
  22. package/src/get-supported-timezones.ts +15 -0
  23. package/src/get-supported-units.ts +15 -0
  24. package/src/index.ts +33 -0
  25. package/src/numbering-systems.generated.ts +1 -0
  26. package/src/timezones.generated.ts +5 -0
  27. package/src/units.generated.ts +4 -0
  28. package/tests/index.test.ts +47 -0
  29. package/tsconfig.json +5 -0
  30. package/index.d.ts +0 -9
  31. package/index.d.ts.map +0 -1
  32. package/index.js +0 -7
  33. package/lib/index.d.ts +0 -9
  34. package/lib/index.d.ts.map +0 -1
  35. package/lib/index.js +0 -2
  36. package/lib/polyfill-force.d.ts +0 -2
  37. package/lib/polyfill-force.d.ts.map +0 -1
  38. package/lib/polyfill-force.js +0 -7
  39. package/lib/polyfill.d.ts +0 -2
  40. package/lib/polyfill.d.ts.map +0 -1
  41. package/lib/polyfill.js +0 -10
  42. package/lib/should-polyfill.d.ts +0 -2
  43. package/lib/should-polyfill.d.ts.map +0 -1
  44. package/lib/should-polyfill.js +0 -3
  45. package/lib/src/calendars.generated.d.ts +0 -3
  46. package/lib/src/calendars.generated.d.ts.map +0 -1
  47. package/lib/src/calendars.generated.js +0 -3
  48. package/lib/src/collations.generated.d.ts +0 -3
  49. package/lib/src/collations.generated.d.ts.map +0 -1
  50. package/lib/src/collations.generated.js +0 -3
  51. package/lib/src/currencies.generated.d.ts +0 -3
  52. package/lib/src/currencies.generated.d.ts.map +0 -1
  53. package/lib/src/currencies.generated.js +0 -3
  54. package/lib/src/get-supported-calendars.d.ts +0 -3
  55. package/lib/src/get-supported-calendars.d.ts.map +0 -1
  56. package/lib/src/get-supported-calendars.js +0 -14
  57. package/lib/src/get-supported-collations.d.ts +0 -3
  58. package/lib/src/get-supported-collations.d.ts.map +0 -1
  59. package/lib/src/get-supported-collations.js +0 -11
  60. package/lib/src/get-supported-currencies.d.ts +0 -3
  61. package/lib/src/get-supported-currencies.d.ts.map +0 -1
  62. package/lib/src/get-supported-currencies.js +0 -40
  63. package/lib/src/get-supported-numbering-systems.d.ts +0 -2
  64. package/lib/src/get-supported-numbering-systems.d.ts.map +0 -1
  65. package/lib/src/get-supported-numbering-systems.js +0 -16
  66. package/lib/src/get-supported-timezones.d.ts +0 -3
  67. package/lib/src/get-supported-timezones.d.ts.map +0 -1
  68. package/lib/src/get-supported-timezones.js +0 -12
  69. package/lib/src/get-supported-units.d.ts +0 -2
  70. package/lib/src/get-supported-units.d.ts.map +0 -1
  71. package/lib/src/get-supported-units.js +0 -12
  72. package/lib/src/index.d.ts +0 -3
  73. package/lib/src/index.d.ts.map +0 -1
  74. package/lib/src/index.js +0 -24
  75. package/lib/src/numbering-systems.generated.d.ts +0 -2
  76. package/lib/src/numbering-systems.generated.d.ts.map +0 -1
  77. package/lib/src/numbering-systems.generated.js +0 -1
  78. package/lib/src/timezones.generated.d.ts +0 -3
  79. package/lib/src/timezones.generated.d.ts.map +0 -1
  80. package/lib/src/timezones.generated.js +0 -3
  81. package/lib/src/units.generated.d.ts +0 -3
  82. package/lib/src/units.generated.d.ts.map +0 -1
  83. package/lib/src/units.generated.js +0 -3
  84. package/polyfill-force.d.ts +0 -2
  85. package/polyfill-force.d.ts.map +0 -1
  86. package/polyfill-force.js +0 -9
  87. package/polyfill.d.ts +0 -2
  88. package/polyfill.d.ts.map +0 -1
  89. package/polyfill.js +0 -12
  90. package/should-polyfill.d.ts +0 -2
  91. package/should-polyfill.d.ts.map +0 -1
  92. package/should-polyfill.js +0 -7
  93. package/src/calendars.generated.d.ts +0 -3
  94. package/src/calendars.generated.d.ts.map +0 -1
  95. package/src/calendars.generated.js +0 -6
  96. package/src/collations.generated.d.ts +0 -3
  97. package/src/collations.generated.d.ts.map +0 -1
  98. package/src/collations.generated.js +0 -6
  99. package/src/currencies.generated.d.ts +0 -3
  100. package/src/currencies.generated.d.ts.map +0 -1
  101. package/src/currencies.generated.js +0 -6
  102. package/src/get-supported-calendars.d.ts +0 -3
  103. package/src/get-supported-calendars.d.ts.map +0 -1
  104. package/src/get-supported-calendars.js +0 -18
  105. package/src/get-supported-collations.d.ts +0 -3
  106. package/src/get-supported-collations.d.ts.map +0 -1
  107. package/src/get-supported-collations.js +0 -15
  108. package/src/get-supported-currencies.d.ts +0 -3
  109. package/src/get-supported-currencies.d.ts.map +0 -1
  110. package/src/get-supported-currencies.js +0 -44
  111. package/src/get-supported-numbering-systems.d.ts +0 -2
  112. package/src/get-supported-numbering-systems.d.ts.map +0 -1
  113. package/src/get-supported-numbering-systems.js +0 -20
  114. package/src/get-supported-timezones.d.ts +0 -3
  115. package/src/get-supported-timezones.d.ts.map +0 -1
  116. package/src/get-supported-timezones.js +0 -16
  117. package/src/get-supported-units.d.ts +0 -2
  118. package/src/get-supported-units.d.ts.map +0 -1
  119. package/src/get-supported-units.js +0 -16
  120. package/src/index.d.ts +0 -3
  121. package/src/index.d.ts.map +0 -1
  122. package/src/index.js +0 -28
  123. package/src/numbering-systems.generated.d.ts +0 -2
  124. package/src/numbering-systems.generated.d.ts.map +0 -1
  125. package/src/numbering-systems.generated.js +0 -4
  126. package/src/timezones.generated.d.ts +0 -3
  127. package/src/timezones.generated.d.ts.map +0 -1
  128. package/src/timezones.generated.js +0 -6
  129. package/src/units.generated.d.ts +0 -3
  130. package/src/units.generated.d.ts.map +0 -1
  131. package/src/units.generated.js +0 -6
package/BUILD ADDED
@@ -0,0 +1,136 @@
1
+ load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
2
+ load("@aspect_rules_js//npm/private:npm_package.bzl", "npm_package")
3
+ load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
4
+ load("@npm//:defs.bzl", "npm_link_all_packages")
5
+ load("//:index.bzl", "ZONES")
6
+ load("//tools:index.bzl", "check_format", "generate_src_file", "ts_compile")
7
+ load("//tools:jest.bzl", "jest_test")
8
+
9
+ npm_link_all_packages(name = "node_modules")
10
+
11
+ PACKAGE_NAME = "intl-enumerator"
12
+
13
+ npm_package(
14
+ name = PACKAGE_NAME,
15
+ srcs = [
16
+ "LICENSE.md",
17
+ "README.md",
18
+ "package.json",
19
+ ":dist",
20
+ ],
21
+ package = "@formatjs/%s" % PACKAGE_NAME,
22
+ visibility = ["//visibility:public"],
23
+ )
24
+
25
+ SRCS = glob([
26
+ "src/**/*.ts",
27
+ "*.ts",
28
+ ])
29
+
30
+ TESTS = glob([
31
+ "tests/*.test.ts",
32
+ ])
33
+
34
+ ts_compile(
35
+ name = "dist",
36
+ srcs = SRCS,
37
+ package = "@formatjs/%s" % PACKAGE_NAME,
38
+ skip_esm = False,
39
+ deps = [],
40
+ )
41
+
42
+ jest_test(
43
+ name = "unit",
44
+ srcs = SRCS + TESTS,
45
+ deps = [],
46
+ )
47
+
48
+ # Test262
49
+ ts_project(
50
+ name = "test262-main-bundle",
51
+ srcs = SRCS,
52
+ declaration = True,
53
+ declaration_map = True,
54
+ extends = "//:tsconfig",
55
+ out_dir = "test262",
56
+ resolve_json_module = True,
57
+ tsconfig = "//:tsconfig.es6",
58
+ deps = [],
59
+ )
60
+
61
+ write_source_files(
62
+ name = "tsconfig_json",
63
+ files = {"tsconfig.json": "//tools:tsconfig.golden.json"},
64
+ )
65
+
66
+ check_format(
67
+ name = "prettier",
68
+ srcs = glob(
69
+ [
70
+ "**/*",
71
+ ],
72
+ exclude = [
73
+ "CHANGELOG.md",
74
+ "src/*.generated.*",
75
+ ],
76
+ ),
77
+ )
78
+
79
+ # calendars
80
+ generate_src_file(
81
+ name = "calendars",
82
+ src = "src/calendars.generated.ts",
83
+ data = [
84
+ "//:node_modules/cldr-bcp47",
85
+ ],
86
+ entry_point = "scripts/calendars.ts",
87
+ )
88
+
89
+ # timezones
90
+ generate_src_file(
91
+ name = "timezones",
92
+ src = "src/timezones.generated.ts",
93
+ args = ["--zone %s" % z for z in ZONES],
94
+ data = [
95
+ ],
96
+ entry_point = "scripts/timezones.ts",
97
+ )
98
+
99
+ # numbering-systems
100
+ write_source_files(
101
+ name = "numbering-systems",
102
+ files = {
103
+ "src/numbering-systems.generated.ts": "//packages/intl-numberformat:src/numbering-systems.generated.ts",
104
+ },
105
+ )
106
+
107
+ # currencies
108
+ generate_src_file(
109
+ name = "currencies",
110
+ src = "src/currencies.generated.ts",
111
+ data = [
112
+ "//:node_modules/cldr-numbers-full",
113
+ ],
114
+ entry_point = "scripts/currencies.ts",
115
+ )
116
+
117
+ # collations
118
+ generate_src_file(
119
+ name = "collations",
120
+ src = "src/collations.generated.ts",
121
+ data = [
122
+ "//:node_modules/cldr-bcp47",
123
+ ],
124
+ entry_point = "scripts/collations.ts",
125
+ )
126
+
127
+ # units
128
+ generate_src_file(
129
+ name = "units",
130
+ src = "src/units.generated.ts",
131
+ data = [
132
+ ":node_modules/@formatjs/ecma402-abstract",
133
+ "//:node_modules/cldr-bcp47",
134
+ ],
135
+ entry_point = "scripts/units.ts",
136
+ )
package/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/intl-enumerator@1.1.1...@formatjs/intl-enumerator@1.1.2) (2022-08-18)
7
+
8
+ **Note:** Version bump only for package @formatjs/intl-enumerator
9
+
10
+ ## [1.1.1](https://github.com/formatjs/formatjs/compare/@formatjs/intl-enumerator@1.1.0...@formatjs/intl-enumerator@1.1.1) (2022-07-16)
11
+
12
+ ### Bug Fixes
13
+
14
+ * **@formatjs/cli-lib:** introduce @formatjs/cli-lib as @formatjs/cli Node API ([7c4ebef](https://github.com/formatjs/formatjs/commit/7c4ebef00a6ac2a197b5007e328306bc8e00b445)), closes [#3625](https://github.com/formatjs/formatjs/issues/3625)
15
+
16
+ # 1.1.0 (2022-07-11)
17
+
18
+ ### Bug Fixes
19
+
20
+ * **@formatjs/intl-enumerator:** fix intl-enumerator build ([a1d95e1](https://github.com/formatjs/formatjs/commit/a1d95e13e21fddf8f13475254daf13d86dd34b6a))
21
+ * **@formatjs/intl-enumerator:** fixes intl.supportedValuesOf units ([#3699](https://github.com/formatjs/formatjs/issues/3699)) ([23c642c](https://github.com/formatjs/formatjs/commit/23c642c31996f6cbad59b374d59b5bb54d5dc6a2))
22
+
23
+ ### Features
24
+
25
+ * **@formatjs/intl-enumerator:** porting of proposal-intl-enumeration to typescript ([#3694](https://github.com/formatjs/formatjs/issues/3694)) ([8c95643](https://github.com/formatjs/formatjs/commit/8c95643ca3128f4e0d0c4cd196dd8773467f7db8))
package/LICENSE.md CHANGED
File without changes
package/README.md CHANGED
File without changes
package/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type {SupportedValuesOf} from './src'
2
+ export type {Calendar} from './src/calendars.generated'
3
+ export type {Collation} from './src/collations.generated'
4
+ export type {Currency} from './src/currencies.generated'
5
+ export type {Timezone} from './src/timezones.generated'
6
+ export type {Unit} from './src/units.generated'
7
+
8
+ export {shouldPolyfill} from './should-polyfill'
9
+ export {supportedValuesOf} from './src'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-enumerator",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Intl.Enumerator polyfill",
5
5
  "keywords": [
6
6
  "intl",
@@ -25,5 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "tslib": "2.4.0"
28
+ },
29
+ "devDependencies": {
30
+ "@formatjs/ecma402-abstract": "1.11.9"
28
31
  }
29
- }
32
+ }
@@ -0,0 +1,8 @@
1
+ import {supportedValuesOf} from './src'
2
+
3
+ Object.defineProperty(Intl, 'supportedValuesOf', {
4
+ value: supportedValuesOf,
5
+ enumerable: true,
6
+ writable: false,
7
+ configurable: false,
8
+ })
package/polyfill.ts ADDED
@@ -0,0 +1,11 @@
1
+ import {shouldPolyfill} from './should-polyfill'
2
+ import {supportedValuesOf} from './src'
3
+
4
+ if (shouldPolyfill()) {
5
+ Object.defineProperty(Intl, 'supportedValuesOf', {
6
+ value: supportedValuesOf,
7
+ enumerable: true,
8
+ writable: false,
9
+ configurable: false,
10
+ })
11
+ }
@@ -0,0 +1,21 @@
1
+ import minimist from 'minimist'
2
+ import {outputFileSync} from 'fs-extra'
3
+ import {keyword} from 'cldr-bcp47/bcp47/calendar.json'
4
+ function main(args: minimist.ParsedArgs) {
5
+ const {out} = args
6
+ const calendars = Object.keys(keyword.u.ca).filter(k => !k.startsWith('_'))
7
+
8
+ // Output numbering systems file
9
+ outputFileSync(
10
+ out,
11
+ `/* @generated */
12
+ // prettier-ignore
13
+ export const calendars = ${JSON.stringify(calendars)} as const
14
+ export type Calendar = typeof calendars[number]
15
+ `
16
+ )
17
+ }
18
+
19
+ if (require.main === module) {
20
+ main(minimist(process.argv))
21
+ }
@@ -0,0 +1,21 @@
1
+ import minimist from 'minimist'
2
+ import {outputFileSync} from 'fs-extra'
3
+ import {keyword} from 'cldr-bcp47/bcp47/collation.json'
4
+ function main(args: minimist.ParsedArgs) {
5
+ const {out} = args
6
+ const collations = Object.keys(keyword.u.co).filter(k => !k.startsWith('_'))
7
+
8
+ // Output numbering systems file
9
+ outputFileSync(
10
+ out,
11
+ `/* @generated */
12
+ // prettier-ignore
13
+ export const collations = ${JSON.stringify(collations)} as const
14
+ export type Collation = typeof collations[number]
15
+ `
16
+ )
17
+ }
18
+
19
+ if (require.main === module) {
20
+ main(minimist(process.argv))
21
+ }
@@ -0,0 +1,21 @@
1
+ import minimist from 'minimist'
2
+ import {outputFileSync} from 'fs-extra'
3
+ import {main as data} from 'cldr-numbers-full/main/en/currencies.json'
4
+ function main(args: minimist.ParsedArgs) {
5
+ const {out} = args
6
+ const currencies = Object.keys(data.en.numbers.currencies)
7
+
8
+ // Output numbering systems file
9
+ outputFileSync(
10
+ out,
11
+ `/* @generated */
12
+ // prettier-ignore
13
+ export const currencies = ${JSON.stringify(currencies)} as const
14
+ export type Currency = typeof currencies[number]
15
+ `
16
+ )
17
+ }
18
+
19
+ if (require.main === module) {
20
+ main(minimist(process.argv))
21
+ }
@@ -0,0 +1,22 @@
1
+ import minimist from 'minimist'
2
+ import {outputFileSync} from 'fs-extra'
3
+ interface Args extends minimist.ParsedArgs {
4
+ zone: string[]
5
+ }
6
+ function main(args: Args) {
7
+ const {out, zone: timezones} = args
8
+
9
+ // Output numbering systems file
10
+ outputFileSync(
11
+ out,
12
+ `/* @generated */
13
+ // prettier-ignore
14
+ export const timezones = ${JSON.stringify(timezones)} as const
15
+ export type Timezone = typeof timezones[number]
16
+ `
17
+ )
18
+ }
19
+
20
+ if (require.main === module) {
21
+ main(minimist<Args>(process.argv))
22
+ }
@@ -0,0 +1,23 @@
1
+ import minimist from 'minimist'
2
+ import {outputFileSync} from 'fs-extra'
3
+ import {SIMPLE_UNITS} from '@formatjs/ecma402-abstract'
4
+
5
+ interface Args extends minimist.ParsedArgs {
6
+ zone: string[]
7
+ }
8
+
9
+ function main(args: Args) {
10
+ const {out} = args
11
+
12
+ outputFileSync(
13
+ out,
14
+ `/* @generated */
15
+ // prettier-ignore
16
+ export const units = ${JSON.stringify(SIMPLE_UNITS)} as const
17
+ export type Unit = typeof units[number]`
18
+ )
19
+ }
20
+
21
+ if (require.main === module) {
22
+ main(minimist<Args>(process.argv))
23
+ }
@@ -0,0 +1,3 @@
1
+ export function shouldPolyfill(): boolean {
2
+ return !('supportedValuesOf' in Intl)
3
+ }
@@ -0,0 +1,5 @@
1
+ /* @generated */
2
+ // prettier-ignore
3
+ export const calendars = ["buddhist","chinese","coptic","dangi","ethioaa","ethiopic","gregory","hebrew","indian","islamic","islamic-civil","islamic-rgsa","islamic-tbla","islamic-umalqura","islamicc","iso8601","japanese","persian","roc"] as const
4
+ export type Calendar = typeof calendars[number]
5
+
@@ -0,0 +1,5 @@
1
+ /* @generated */
2
+ // prettier-ignore
3
+ export const collations = ["big5han","compat","dict","direct","ducet","emoji","eor","gb2312","phonebk","phonetic","pinyin","reformed","search","searchjl","standard","stroke","trad","unihan","zhuyin"] as const
4
+ export type Collation = typeof collations[number]
5
+
@@ -0,0 +1,5 @@
1
+ /* @generated */
2
+ // prettier-ignore
3
+ export const currencies = ["ADP","AED","AFA","AFN","ALK","ALL","AMD","ANG","AOA","AOK","AON","AOR","ARA","ARL","ARM","ARP","ARS","ATS","AUD","AWG","AZM","AZN","BAD","BAM","BAN","BBD","BDT","BEC","BEF","BEL","BGL","BGM","BGN","BGO","BHD","BIF","BMD","BND","BOB","BOL","BOP","BOV","BRB","BRC","BRE","BRL","BRN","BRR","BRZ","BSD","BTN","BUK","BWP","BYB","BYN","BYR","BZD","CAD","CDF","CHE","CHF","CHW","CLE","CLF","CLP","CNH","CNX","CNY","COP","COU","CRC","CSD","CSK","CUC","CUP","CVE","CYP","CZK","DDM","DEM","DJF","DKK","DOP","DZD","ECS","ECV","EEK","EGP","ERN","ESA","ESB","ESP","ETB","EUR","FIM","FJD","FKP","FRF","GBP","GEK","GEL","GHC","GHS","GIP","GMD","GNF","GNS","GQE","GRD","GTQ","GWE","GWP","GYD","HKD","HNL","HRD","HRK","HTG","HUF","IDR","IEP","ILP","ILR","ILS","INR","IQD","IRR","ISJ","ISK","ITL","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRH","KRO","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LTL","LTT","LUC","LUF","LUL","LVL","LVR","LYD","MAD","MAF","MCF","MDC","MDL","MGA","MGF","MKD","MKN","MLF","MMK","MNT","MOP","MRO","MRU","MTL","MTP","MUR","MVP","MVR","MWK","MXN","MXP","MXV","MYR","MZE","MZM","MZN","NAD","NGN","NIC","NIO","NLG","NOK","NPR","NZD","OMR","PAB","PEI","PEN","PES","PGK","PHP","PKR","PLN","PLZ","PTE","PYG","QAR","RHD","ROL","RON","RSD","RUB","RUR","RWF","SAR","SBD","SCR","SDD","SDG","SDP","SEK","SGD","SHP","SIT","SKK","SLL","SOS","SRD","SRG","SSP","STD","STN","SUR","SVC","SYP","SZL","THB","TJR","TJS","TMM","TMT","TND","TOP","TPE","TRL","TRY","TTD","TWD","TZS","UAH","UAK","UGS","UGX","USD","USN","USS","UYI","UYP","UYU","UYW","UZS","VEB","VEF","VES","VND","VNN","VUV","WST","XAF","XAG","XAU","XBA","XBB","XBC","XBD","XCD","XDR","XEU","XFO","XFU","XOF","XPD","XPF","XPT","XRE","XSU","XTS","XUA","XXX","YDD","YER","YUD","YUM","YUN","YUR","ZAL","ZAR","ZMK","ZMW","ZRN","ZRZ","ZWD","ZWL","ZWR"] as const
4
+ export type Currency = typeof currencies[number]
5
+
@@ -0,0 +1,17 @@
1
+ import type {Calendar} from './calendars.generated'
2
+ import {calendars} from './calendars.generated'
3
+
4
+ function isSupportedCalendar(item: Calendar): boolean {
5
+ try {
6
+ const dateTimeFormat = new Intl.DateTimeFormat('en-u-ca' + item)
7
+ const options = dateTimeFormat.resolvedOptions().calendar
8
+
9
+ if (item !== 'gregory' || options !== 'gregory') return true
10
+ } catch (_err) {}
11
+
12
+ return false
13
+ }
14
+
15
+ export function getSupportedCalendars(): Calendar[] {
16
+ return calendars.filter(isSupportedCalendar)
17
+ }
@@ -0,0 +1,16 @@
1
+ import type {Collation} from './collations.generated'
2
+ import {collations} from './collations.generated'
3
+
4
+ function isSupported(collation: Collation): boolean {
5
+ try {
6
+ return (
7
+ Intl.Collator('en-u-co-' + collation).resolvedOptions().locale === 'en'
8
+ )
9
+ } catch (_err) {}
10
+
11
+ return false
12
+ }
13
+
14
+ export function getSupportedCollations(): Collation[] {
15
+ return collations.filter(isSupported)
16
+ }
@@ -0,0 +1,48 @@
1
+ import type {Currency} from './currencies.generated'
2
+ import {currencies} from './currencies.generated'
3
+
4
+ function isSupportedCurrency(currency: Currency): boolean {
5
+ try {
6
+ const numberFormat = new Intl.NumberFormat('en', {
7
+ style: 'currency',
8
+ currencyDisplay: 'name',
9
+ currency,
10
+ })
11
+
12
+ const format = numberFormat.format(123)
13
+
14
+ if (
15
+ format.substring(0, 3) !== currency &&
16
+ format.substring(format.length - 3) !== currency
17
+ ) {
18
+ return true
19
+ }
20
+ } catch (_err) {}
21
+
22
+ return false
23
+ }
24
+
25
+ export function getSupportedCurrencies(): Currency[] {
26
+ const ATOZ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
27
+ const supportedCurrencies: Currency[] = []
28
+
29
+ for (const currency of currencies) {
30
+ if (currency.length === 3) {
31
+ if (isSupportedCurrency(currency)) {
32
+ supportedCurrencies.push(currency)
33
+ }
34
+ } else if (currency.length === 5 && currency[3] === '~') {
35
+ const start = ATOZ.indexOf(currency[2])
36
+ const end = ATOZ.indexOf(currency[4])
37
+
38
+ for (let i = start; i <= end; i++) {
39
+ const currentCurrency = (currency.substring(0, 2) + ATOZ[i]) as Currency
40
+ if (isSupportedCurrency(currentCurrency)) {
41
+ supportedCurrencies.push(currentCurrency)
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ return supportedCurrencies
48
+ }
@@ -0,0 +1,21 @@
1
+ import {numberingSystemNames} from './numbering-systems.generated'
2
+
3
+ function isSupportedNumberingSystem(system: string): boolean {
4
+ try {
5
+ const numberFormat = new Intl.NumberFormat('en-u-nu-' + system)
6
+ const options = numberFormat.resolvedOptions().numberingSystem
7
+
8
+ if (
9
+ (options === system && system === 'latn') ||
10
+ numberFormat.format(123) !== '123'
11
+ ) {
12
+ return true
13
+ }
14
+ } catch (_err) {}
15
+
16
+ return false
17
+ }
18
+
19
+ export function getSupportedNumberingSystems(): string[] {
20
+ return numberingSystemNames.filter(isSupportedNumberingSystem)
21
+ }
@@ -0,0 +1,15 @@
1
+ import type {Timezone} from './timezones.generated'
2
+ import {timezones} from './timezones.generated'
3
+
4
+ function isSupported(timeZone: Timezone): boolean {
5
+ try {
6
+ const formatter = new Intl.DateTimeFormat('en', {timeZone})
7
+ return formatter.resolvedOptions().timeZone === timeZone
8
+ } catch (_err) {}
9
+
10
+ return false
11
+ }
12
+
13
+ export function getSupportedTimeZones(): Timezone[] {
14
+ return timezones.filter(isSupported)
15
+ }
@@ -0,0 +1,15 @@
1
+ import type {Unit} from './units.generated'
2
+ import {units} from './units.generated'
3
+
4
+ function isSupported(unit: Unit): boolean {
5
+ try {
6
+ const formatter = new Intl.NumberFormat('en', {style: 'unit', unit})
7
+ return formatter.resolvedOptions().unit === unit
8
+ } catch (_err) {}
9
+
10
+ return false
11
+ }
12
+
13
+ export function getSupportedUnits() {
14
+ return units.filter(isSupported)
15
+ }
package/src/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ import {getSupportedCalendars} from './get-supported-calendars'
2
+ import {getSupportedCollations} from './get-supported-collations'
3
+ import {getSupportedCurrencies} from './get-supported-currencies'
4
+ import {getSupportedNumberingSystems} from './get-supported-numbering-systems'
5
+ import {getSupportedTimeZones} from './get-supported-timezones'
6
+ import {getSupportedUnits} from './get-supported-units'
7
+
8
+ export type SupportedValuesOf =
9
+ | 'calendar'
10
+ | 'collation'
11
+ | 'currency'
12
+ | 'numberingSystem'
13
+ | 'timeZone'
14
+ | 'unit'
15
+
16
+ export function supportedValuesOf(key: SupportedValuesOf): string[] {
17
+ switch (key) {
18
+ case 'calendar':
19
+ return getSupportedCalendars()
20
+ case 'collation':
21
+ return getSupportedCollations()
22
+ case 'currency':
23
+ return getSupportedCurrencies()
24
+ case 'numberingSystem':
25
+ return getSupportedNumberingSystems()
26
+ case 'timeZone':
27
+ return getSupportedTimeZones()
28
+ case 'unit':
29
+ return getSupportedUnits()
30
+ default:
31
+ throw RangeError('Invalid key: ' + key)
32
+ }
33
+ }
@@ -0,0 +1 @@
1
+ export const numberingSystemNames: ReadonlyArray<string> = ["adlm","ahom","arab","arabext","armn","armnlow","bali","beng","bhks","brah","cakm","cham","cyrl","deva","diak","ethi","fullwide","geor","gong","gonm","grek","greklow","gujr","guru","hanidays","hanidec","hans","hansfin","hant","hantfin","hebr","hmng","hmnp","java","jpan","jpanfin","jpanyear","kali","khmr","knda","lana","lanatham","laoo","latn","lepc","limb","mathbold","mathdbl","mathmono","mathsanb","mathsans","mlym","modi","mong","mroo","mtei","mymr","mymrshan","mymrtlng","newa","nkoo","olck","orya","osma","rohg","roman","romanlow","saur","segment","shrd","sind","sinh","sora","sund","takr","talu","taml","tamldec","telu","thai","tibt","tirh","tnsa","vaii","wara","wcho"];
@@ -0,0 +1,5 @@
1
+ /* @generated */
2
+ // prettier-ignore
3
+ export const timezones = ["Africa/Abidjan","Africa/Accra","Africa/Addis_Ababa","Africa/Algiers","Africa/Asmara","Africa/Bamako","Africa/Bangui","Africa/Banjul","Africa/Bissau","Africa/Blantyre","Africa/Brazzaville","Africa/Bujumbura","Africa/Cairo","Africa/Casablanca","Africa/Ceuta","Africa/Conakry","Africa/Dakar","Africa/Dar_es_Salaam","Africa/Djibouti","Africa/Douala","Africa/El_Aaiun","Africa/Freetown","Africa/Gaborone","Africa/Harare","Africa/Johannesburg","Africa/Juba","Africa/Kampala","Africa/Khartoum","Africa/Kigali","Africa/Kinshasa","Africa/Lagos","Africa/Libreville","Africa/Lome","Africa/Luanda","Africa/Lubumbashi","Africa/Lusaka","Africa/Malabo","Africa/Maputo","Africa/Maseru","Africa/Mbabane","Africa/Mogadishu","Africa/Monrovia","Africa/Nairobi","Africa/Ndjamena","Africa/Niamey","Africa/Nouakchott","Africa/Ouagadougou","Africa/Porto-Novo","Africa/Sao_Tome","Africa/Tripoli","Africa/Tunis","Africa/Windhoek","America/Adak","America/Anchorage","America/Anguilla","America/Antigua","America/Araguaina","America/Argentina/Buenos_Aires","America/Argentina/Catamarca","America/Argentina/Cordoba","America/Argentina/Jujuy","America/Argentina/La_Rioja","America/Argentina/Mendoza","America/Argentina/Rio_Gallegos","America/Argentina/Salta","America/Argentina/San_Juan","America/Argentina/San_Luis","America/Argentina/Tucuman","America/Argentina/Ushuaia","America/Aruba","America/Asuncion","America/Atikokan","America/Bahia_Banderas","America/Bahia","America/Barbados","America/Belem","America/Belize","America/Blanc-Sablon","America/Boa_Vista","America/Bogota","America/Boise","America/Cambridge_Bay","America/Campo_Grande","America/Cancun","America/Caracas","America/Cayenne","America/Cayman","America/Chicago","America/Chihuahua","America/Costa_Rica","America/Creston","America/Cuiaba","America/Curacao","America/Danmarkshavn","America/Dawson_Creek","America/Dawson","America/Denver","America/Detroit","America/Dominica","America/Edmonton","America/Eirunepe","America/El_Salvador","America/Fort_Nelson","America/Fortaleza","America/Glace_Bay","America/Goose_Bay","America/Grand_Turk","America/Grenada","America/Guadeloupe","America/Guatemala","America/Guayaquil","America/Guyana","America/Halifax","America/Havana","America/Hermosillo","America/Indiana/Indianapolis","America/Indiana/Knox","America/Indiana/Marengo","America/Indiana/Petersburg","America/Indiana/Tell_City","America/Indiana/Vevay","America/Indiana/Vincennes","America/Indiana/Winamac","America/Inuvik","America/Iqaluit","America/Jamaica","America/Juneau","America/Kentucky/Louisville","America/Kentucky/Monticello","America/Kralendijk","America/La_Paz","America/Lima","America/Los_Angeles","America/Lower_Princes","America/Maceio","America/Managua","America/Manaus","America/Marigot","America/Martinique","America/Matamoros","America/Mazatlan","America/Menominee","America/Merida","America/Metlakatla","America/Mexico_City","America/Miquelon","America/Moncton","America/Monterrey","America/Montevideo","America/Montserrat","America/Nassau","America/New_York","America/Nipigon","America/Nome","America/Noronha","America/North_Dakota/Beulah","America/North_Dakota/Center","America/North_Dakota/New_Salem","America/Nuuk","America/Ojinaga","America/Panama","America/Pangnirtung","America/Paramaribo","America/Phoenix","America/Port_of_Spain","America/Port-au-Prince","America/Porto_Velho","America/Puerto_Rico","America/Punta_Arenas","America/Rainy_River","America/Rankin_Inlet","America/Recife","America/Regina","America/Resolute","America/Rio_Branco","America/Santarem","America/Santiago","America/Santo_Domingo","America/Sao_Paulo","America/Scoresbysund","America/Sitka","America/St_Barthelemy","America/St_Johns","America/St_Kitts","America/St_Lucia","America/St_Thomas","America/St_Vincent","America/Swift_Current","America/Tegucigalpa","America/Thule","America/Thunder_Bay","America/Tijuana","America/Toronto","America/Tortola","America/Vancouver","America/Whitehorse","America/Winnipeg","America/Yakutat","America/Yellowknife","Antarctica/Casey","Antarctica/Davis","Antarctica/DumontDUrville","Antarctica/Macquarie","Antarctica/Mawson","Antarctica/McMurdo","Antarctica/Palmer","Antarctica/Rothera","Antarctica/Syowa","Antarctica/Troll","Antarctica/Vostok","Arctic/Longyearbyen","Asia/Aden","Asia/Almaty","Asia/Amman","Asia/Anadyr","Asia/Aqtau","Asia/Aqtobe","Asia/Ashgabat","Asia/Atyrau","Asia/Baghdad","Asia/Bahrain","Asia/Baku","Asia/Bangkok","Asia/Barnaul","Asia/Beirut","Asia/Bishkek","Asia/Brunei","Asia/Chita","Asia/Choibalsan","Asia/Colombo","Asia/Damascus","Asia/Dhaka","Asia/Dili","Asia/Dubai","Asia/Dushanbe","Asia/Famagusta","Asia/Gaza","Asia/Hebron","Asia/Ho_Chi_Minh","Asia/Hong_Kong","Asia/Hovd","Asia/Irkutsk","Asia/Jakarta","Asia/Jayapura","Asia/Jerusalem","Asia/Kabul","Asia/Kamchatka","Asia/Karachi","Asia/Kathmandu","Asia/Khandyga","Asia/Kolkata","Asia/Krasnoyarsk","Asia/Kuala_Lumpur","Asia/Kuching","Asia/Kuwait","Asia/Macau","Asia/Magadan","Asia/Makassar","Asia/Manila","Asia/Muscat","Asia/Nicosia","Asia/Novokuznetsk","Asia/Novosibirsk","Asia/Omsk","Asia/Oral","Asia/Phnom_Penh","Asia/Pontianak","Asia/Pyongyang","Asia/Qatar","Asia/Qostanay","Asia/Qyzylorda","Asia/Riyadh","Asia/Sakhalin","Asia/Samarkand","Asia/Seoul","Asia/Shanghai","Asia/Singapore","Asia/Srednekolymsk","Asia/Taipei","Asia/Tashkent","Asia/Tbilisi","Asia/Tehran","Asia/Thimphu","Asia/Tokyo","Asia/Tomsk","Asia/Ulaanbaatar","Asia/Urumqi","Asia/Ust-Nera","Asia/Vientiane","Asia/Vladivostok","Asia/Yakutsk","Asia/Yangon","Asia/Yekaterinburg","Asia/Yerevan","Atlantic/Azores","Atlantic/Bermuda","Atlantic/Canary","Atlantic/Cape_Verde","Atlantic/Faroe","Atlantic/Madeira","Atlantic/Reykjavik","Atlantic/South_Georgia","Atlantic/St_Helena","Atlantic/Stanley","Australia/Adelaide","Australia/Brisbane","Australia/Broken_Hill","Australia/Currie","Australia/Darwin","Australia/Eucla","Australia/Hobart","Australia/Lindeman","Australia/Lord_Howe","Australia/Melbourne","Australia/Perth","Australia/Sydney","Europe/Amsterdam","Europe/Andorra","Europe/Astrakhan","Europe/Athens","Europe/Belgrade","Europe/Berlin","Europe/Bratislava","Europe/Brussels","Europe/Bucharest","Europe/Budapest","Europe/Busingen","Europe/Chisinau","Europe/Copenhagen","Europe/Dublin","Europe/Gibraltar","Europe/Guernsey","Europe/Helsinki","Europe/Isle_of_Man","Europe/Istanbul","Europe/Jersey","Europe/Kaliningrad","Europe/Kiev","Europe/Kirov","Europe/Lisbon","Europe/Ljubljana","Europe/London","Europe/Luxembourg","Europe/Madrid","Europe/Malta","Europe/Mariehamn","Europe/Minsk","Europe/Monaco","Europe/Moscow","Europe/Oslo","Europe/Paris","Europe/Podgorica","Europe/Prague","Europe/Riga","Europe/Rome","Europe/Samara","Europe/San_Marino","Europe/Sarajevo","Europe/Saratov","Europe/Simferopol","Europe/Skopje","Europe/Sofia","Europe/Stockholm","Europe/Tallinn","Europe/Tirane","Europe/Ulyanovsk","Europe/Uzhgorod","Europe/Vaduz","Europe/Vatican","Europe/Vienna","Europe/Vilnius","Europe/Volgograd","Europe/Warsaw","Europe/Zagreb","Europe/Zaporozhye","Europe/Zurich","Indian/Antananarivo","Indian/Chagos","Indian/Christmas","Indian/Cocos","Indian/Comoro","Indian/Kerguelen","Indian/Mahe","Indian/Maldives","Indian/Mauritius","Indian/Mayotte","Indian/Reunion","Pacific/Apia","Pacific/Auckland","Pacific/Bougainville","Pacific/Chatham","Pacific/Chuuk","Pacific/Easter","Pacific/Efate","Pacific/Enderbury","Pacific/Fakaofo","Pacific/Fiji","Pacific/Funafuti","Pacific/Galapagos","Pacific/Gambier","Pacific/Guadalcanal","Pacific/Guam","Pacific/Honolulu","Pacific/Kiritimati","Pacific/Kosrae","Pacific/Kwajalein","Pacific/Majuro","Pacific/Marquesas","Pacific/Midway","Pacific/Nauru","Pacific/Niue","Pacific/Norfolk","Pacific/Noumea","Pacific/Pago_Pago","Pacific/Palau","Pacific/Pitcairn","Pacific/Pohnpei","Pacific/Port_Moresby","Pacific/Rarotonga","Pacific/Saipan","Pacific/Tahiti","Pacific/Tarawa","Pacific/Tongatapu","Pacific/Wake","Pacific/Wallis"] as const
4
+ export type Timezone = typeof timezones[number]
5
+
@@ -0,0 +1,4 @@
1
+ /* @generated */
2
+ // prettier-ignore
3
+ export const units = ["degree","acre","hectare","percent","bit","byte","gigabit","gigabyte","kilobit","kilobyte","megabit","megabyte","petabyte","terabit","terabyte","day","hour","millisecond","minute","month","second","week","year","centimeter","foot","inch","kilometer","meter","mile-scandinavian","mile","millimeter","yard","gram","kilogram","ounce","pound","stone","celsius","fahrenheit","fluid-ounce","gallon","liter","milliliter"] as const
4
+ export type Unit = typeof units[number]
@@ -0,0 +1,47 @@
1
+ import {supportedValuesOf} from '../src'
2
+
3
+ describe('Intl.supportedValueOf("calendar")', () => {
4
+ it('should return an array of supported calendars', () => {
5
+ expect(supportedValuesOf('calendar')).toEqual(expect.any(Array))
6
+ })
7
+
8
+ it('should throw a range error when given an unsupported or misspelled key', () => {
9
+ // @ts-expect-error
10
+ expect(() => supportedValuesOf('calendars')).toThrowError(
11
+ 'Invalid key: calendars'
12
+ )
13
+
14
+ // @ts-expect-error
15
+ expect(() => supportedValuesOf('calendarz')).toThrowError(RangeError)
16
+ })
17
+ })
18
+
19
+ describe('Intl.supportedValueOf("collation")', () => {
20
+ it('should return an array of supported collations', () => {
21
+ expect(supportedValuesOf('collation')).toEqual(expect.any(Array))
22
+ })
23
+ })
24
+
25
+ describe('Intl.supportedValueOf("currency")', () => {
26
+ it('should return an array of supported currencies', () => {
27
+ expect(supportedValuesOf('currency')).toEqual(expect.any(Array))
28
+ })
29
+ })
30
+
31
+ describe('Intl.supportedValueOf("numberingSystem")', () => {
32
+ it('should return an array of supported numbering systems', () => {
33
+ expect(supportedValuesOf('numberingSystem')).toEqual(expect.any(Array))
34
+ })
35
+ })
36
+
37
+ describe('Intl.supportedValueOf("timeZone")', () => {
38
+ it('should return an array of supported time zones', () => {
39
+ expect(supportedValuesOf('timeZone')).toEqual(expect.any(Array))
40
+ })
41
+ })
42
+
43
+ describe('Intl.supportedValueOf("unit")', () => {
44
+ it('should return an array of supported units', () => {
45
+ expect(supportedValuesOf('unit')).toEqual(expect.any(Array))
46
+ })
47
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ // @generated
2
+ {
3
+ // This is purely for IDE, not for compilation
4
+ "extends": "../../tsconfig.json"
5
+ }
package/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export type { SupportedValuesOf } from './src';
2
- export type { Calendar } from './src/calendars.generated';
3
- export type { Collation } from './src/collations.generated';
4
- export type { Currency } from './src/currencies.generated';
5
- export type { Timezone } from './src/timezones.generated';
6
- export type { Unit } from './src/units.generated';
7
- export { shouldPolyfill } from './should-polyfill';
8
- export { supportedValuesOf } from './src';
9
- //# sourceMappingURL=index.d.ts.map