Intl.supportedValuesOf Lists Calendar And Unit Values
List calendars, units, currencies, and time zones with Intl.supportedValuesOf, then feed a supported unit into NumberFormat.
Code
const calendars = Intl.supportedValuesOf('calendar');
const units = Intl.supportedValuesOf('unit');
const currencies = Intl.supportedValuesOf('currency');
const zones = Intl.supportedValuesOf('timeZone');
console.log('calendars:', calendars.length, '| sample:', calendars.slice(0, 4).join(','));
console.log('units:', units.length, '| sample:', units.slice(0, 5).join(','));
console.log('currencies:', currencies.length, '| sample:', currencies.slice(0, 5).join(','));
console.log('time zones:', zones.length, '| has Europe/London:', zones.includes('Europe/London'));
for (const key of ['calendar', 'currency', 'numberingSystem', 'timeZone', 'unit']) {
console.log(key + ':', Intl.supportedValuesOf(key).length);
}
const unit = units.includes('meter') ? 'meter' : units[0];
const formatter = new Intl.NumberFormat('en-US', { style: 'unit', unit, unitDisplay: 'long' });
console.log('formatted:', formatter.format(3));
const supported = new Set(Intl.supportedValuesOf('currency'));
console.log('EUR supported:', supported.has('EUR'));
console.log('XYZ supported:', supported.has('XYZ'));Output
Captured from a sandboxed run of this snippet in the build pipeline.
calendars: 18 | sample: buddhist,chinese,coptic,dangi
units: 45 | sample: acre,bit,byte,celsius,centimeter
currencies: 162 | sample: AED,AFN,ALL,AMD,ANG
time zones: 418 | has Europe/London: true
calendar: 18
currency: 162
numberingSystem: 78
timeZone: 418
unit: 45
formatted: 3 meters
EUR supported: true
XYZ supported: falseWhat the code does
The loop for (const key of ['calendar', 'currency', 'numberingSystem', 'timeZone', 'unit']) is the only repeated construct.
Top-level bindings calendars, units, currencies, zones hold the demo state — nothing sits inside a function scope.
Applying it
The run emits 7 labeled sections — calendars:, units:, currencies:, time zones:, formatted:, EUR supported:, XYZ supported: — one per step.
Statements that matter
const supported = new Set(Intl.supportedValuesOf('currency'));
const formatter = new Intl.NumberFormat('en-US', { style: 'unit', unit, unitDisplay: 'long' });
const currencies = Intl.supportedValuesOf('currency');
Interactive Tools for This Topic
Age CalculatorCalculate exact age in years, months, and days between a birth date and a reference date, plus total days and the next birthday countdown.Business Days CalculatorCount the weekdays between two dates, excluding weekends and any holidays you list, and see how many calendar and weekend days are involved.CSS Unit ConverterConvert a length between px, rem, em, pt, pc, in, cm, mm, and percent using a configurable root font size, following the 96dpi CSS definition.Dotenv File ParserParse .env file content into a JSON object, handling comments, export prefixes, single quotes, and double-quoted escape sequences.
FAQ
- Can I paste this into a project as-is?
- Yes. Paste it in and run; no package manager step is needed. Its state lives in module-level bindings: `calendars`, `units`, `currencies`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.