@formatjs/intl-supportedvaluesof 2.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.
- package/BUILD.bazel +135 -0
- package/CHANGELOG.md +249 -0
- package/LICENSE.md +9 -0
- package/README.md +270 -0
- package/index.ts +9 -0
- package/package.json +33 -0
- package/polyfill-force.ts +8 -0
- package/polyfill.ts +11 -0
- package/scripts/calendars.ts +21 -0
- package/scripts/collations.ts +21 -0
- package/scripts/currencies.ts +21 -0
- package/scripts/timezones.ts +22 -0
- package/scripts/units.ts +23 -0
- package/should-polyfill.ts +3 -0
- package/src/calendars.generated.ts +4 -0
- package/src/collations.generated.ts +4 -0
- package/src/currencies.generated.ts +4 -0
- package/src/get-supported-calendars.ts +32 -0
- package/src/get-supported-collations.ts +30 -0
- package/src/get-supported-currencies.ts +62 -0
- package/src/get-supported-numbering-systems.ts +35 -0
- package/src/get-supported-timezones.ts +29 -0
- package/src/get-supported-units.ts +73 -0
- package/src/index.ts +75 -0
- package/src/memoize.ts +19 -0
- package/src/numbering-systems.generated.ts +99 -0
- package/src/timezones.generated.ts +4 -0
- package/src/units.generated.ts +4 -0
- package/tests/index.test.ts +155 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,4 @@
|
|
|
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/Ciudad_Juarez","America/Costa_Rica","America/Coyhaique","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/Kyiv","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/Kanton","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]
|
|
@@ -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,155 @@
|
|
|
1
|
+
import {supportedValuesOf} from '../src/index.js'
|
|
2
|
+
import {describe, expect, it} from 'vitest'
|
|
3
|
+
|
|
4
|
+
describe('Intl.supportedValuesOf', () => {
|
|
5
|
+
describe('ECMA-402 spec compliance', () => {
|
|
6
|
+
it('should return an array for valid keys', () => {
|
|
7
|
+
// ECMA-402 Spec: Must return an array
|
|
8
|
+
const result = supportedValuesOf('calendar')
|
|
9
|
+
expect(Array.isArray(result)).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('should throw RangeError for invalid key', () => {
|
|
13
|
+
// ECMA-402 Spec: Throw RangeError for invalid keys
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
expect(() => supportedValuesOf('invalid')).toThrow(RangeError)
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
expect(() => supportedValuesOf('calendars')).toThrowError(
|
|
18
|
+
'Invalid key: calendars'
|
|
19
|
+
)
|
|
20
|
+
// @ts-expect-error
|
|
21
|
+
expect(() => supportedValuesOf('calendarz')).toThrowError(RangeError)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('should return sorted arrays', () => {
|
|
25
|
+
// ECMA-402 Spec: Results must be sorted lexicographically
|
|
26
|
+
const keys = [
|
|
27
|
+
'calendar',
|
|
28
|
+
'collation',
|
|
29
|
+
'currency',
|
|
30
|
+
'numberingSystem',
|
|
31
|
+
'timeZone',
|
|
32
|
+
'unit',
|
|
33
|
+
] as const
|
|
34
|
+
|
|
35
|
+
for (const key of keys) {
|
|
36
|
+
const result = supportedValuesOf(key)
|
|
37
|
+
const sorted = [...result].sort()
|
|
38
|
+
expect(result).toEqual(sorted)
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should return non-empty arrays for all keys', () => {
|
|
43
|
+
// Implementation: All keys must return at least some supported values
|
|
44
|
+
const keys = [
|
|
45
|
+
'calendar',
|
|
46
|
+
'collation',
|
|
47
|
+
'currency',
|
|
48
|
+
'numberingSystem',
|
|
49
|
+
'timeZone',
|
|
50
|
+
'unit',
|
|
51
|
+
] as const
|
|
52
|
+
|
|
53
|
+
for (const key of keys) {
|
|
54
|
+
const result = supportedValuesOf(key)
|
|
55
|
+
expect(result.length).toBeGreaterThan(0)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('should return unique values', () => {
|
|
60
|
+
// ECMA-402 Spec: Array must contain unique values
|
|
61
|
+
const keys = [
|
|
62
|
+
'calendar',
|
|
63
|
+
'collation',
|
|
64
|
+
'currency',
|
|
65
|
+
'numberingSystem',
|
|
66
|
+
'timeZone',
|
|
67
|
+
'unit',
|
|
68
|
+
] as const
|
|
69
|
+
|
|
70
|
+
for (const key of keys) {
|
|
71
|
+
const result = supportedValuesOf(key)
|
|
72
|
+
const unique = [...new Set(result)]
|
|
73
|
+
expect(result).toEqual(unique)
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe('calendar', () => {
|
|
79
|
+
it('should return an array of supported calendars', () => {
|
|
80
|
+
const result = supportedValuesOf('calendar')
|
|
81
|
+
expect(result).toEqual(expect.any(Array))
|
|
82
|
+
expect(result.length).toBeGreaterThan(0)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('should include gregorian calendar', () => {
|
|
86
|
+
// Implementation: Gregorian calendar should always be supported
|
|
87
|
+
const result = supportedValuesOf('calendar')
|
|
88
|
+
expect(result).toContain('gregory')
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
describe('collation', () => {
|
|
93
|
+
it('should return an array of supported collations', () => {
|
|
94
|
+
const result = supportedValuesOf('collation')
|
|
95
|
+
expect(result).toEqual(expect.any(Array))
|
|
96
|
+
expect(result.length).toBeGreaterThan(0)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
describe('currency', () => {
|
|
101
|
+
it('should return an array of supported currencies', () => {
|
|
102
|
+
const result = supportedValuesOf('currency')
|
|
103
|
+
expect(result).toEqual(expect.any(Array))
|
|
104
|
+
expect(result.length).toBeGreaterThan(0)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('should include common currencies', () => {
|
|
108
|
+
// Implementation: Common currencies should be supported
|
|
109
|
+
const result = supportedValuesOf('currency')
|
|
110
|
+
expect(result).toContain('USD')
|
|
111
|
+
expect(result).toContain('EUR')
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('numberingSystem', () => {
|
|
116
|
+
it('should return an array of supported numbering systems', () => {
|
|
117
|
+
const result = supportedValuesOf('numberingSystem')
|
|
118
|
+
expect(result).toEqual(expect.any(Array))
|
|
119
|
+
expect(result.length).toBeGreaterThan(0)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('should include latin numbering system', () => {
|
|
123
|
+
// Implementation: Latin numbering system should always be supported
|
|
124
|
+
const result = supportedValuesOf('numberingSystem')
|
|
125
|
+
expect(result).toContain('latn')
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
describe('timeZone', () => {
|
|
130
|
+
it('should return an array of supported time zones', () => {
|
|
131
|
+
const result = supportedValuesOf('timeZone')
|
|
132
|
+
expect(result).toEqual(expect.any(Array))
|
|
133
|
+
expect(result.length).toBeGreaterThan(0)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('should include common IANA timezones', () => {
|
|
137
|
+
// Implementation: Common IANA timezones should be supported
|
|
138
|
+
const result = supportedValuesOf('timeZone')
|
|
139
|
+
// Test for a commonly available timezone
|
|
140
|
+
const hasCommonTimezone =
|
|
141
|
+
result.includes('America/New_York') ||
|
|
142
|
+
result.includes('Europe/London') ||
|
|
143
|
+
result.includes('Asia/Tokyo')
|
|
144
|
+
expect(hasCommonTimezone).toBe(true)
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
describe('unit', () => {
|
|
149
|
+
it('should return an array of supported units', () => {
|
|
150
|
+
const result = supportedValuesOf('unit')
|
|
151
|
+
expect(result).toEqual(expect.any(Array))
|
|
152
|
+
expect(result.length).toBeGreaterThan(0)
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
})
|