Intl.supportedValuesOf Lists Calendar And Unit Values

List calendars, units, currencies, and time zones with Intl.supportedValuesOf, then feed a supported unit into NumberFormat.

JavascriptConfig Management

Code

javascriptsnippet
21 lines
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: false

What 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

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`.