FormatJS

A polyfill/ponyfill for Intl.supportedValuesOf.

npm Version size

Installation

npm i @formatjs/intl-supportedvaluesof

Requirements

Usage

Simple

import '@formatjs/intl-supportedvaluesof/polyfill.js'

Dynamic import + capability detection

async function polyfill() {
  // This platform already supports Intl.supportedValuesOf
  if (shouldPolyfill()) {
    await import('@formatjs/intl-supportedvaluesof/polyfill.js')
  }
  // Alternatively, force the polyfill regardless of support
  await import('@formatjs/intl-supportedvaluesof/polyfill-force.js')
}

Native Hermes SDK

The shared Hermes SDK also provides Intl.supportedValuesOf. Build and extract it on Linux, then link @formatjs_intl_getcanonicallocales_hermes//:supported_values in the consumer. It contains a prebuilt Rust archive; consumers need Hermes and a C++ toolchain, not a Rust compiler. See the SDK guide for desktop and Android packages and installation of all twelve APIs.

Install trusted Intl.DateTimeFormat, Intl.NumberFormat and Intl.Collator implementations first. Rust filters CLDR/IANA candidates against those formatters' actual capabilities. Missing formatters produce empty categories; the installer does not supply the formatters themselves.

#include <formatjs/hermes/supported_values.h>

formatjs::installSupportedValuesOf(*runtime);

For bytecode-only extension startup, compile the SDK's js/extensions.js with the matching hermesc, evaluate it to obtain extensions, then call:

formatjs::installSupportedValuesOf(*runtime, extensions);

For Hermes core/contrib registration, add js/31-IntlSupportedValuesOf.js to the extension source list and call the same two-argument installer from its C++ dispatcher. See the SDK instructions and standalone consumer.

Tests

The Bazel :test262 target runs the upstream suite against a reviewed failure baseline. A green baseline check does not mean every test passed. See the conformance report; run bazel test //packages/intl-supportedvaluesof:test262-strict to require zero failures.

//packages/intl-supportedvaluesof:rust_conformance_test compares every Rust output list with TypeScript using real host formatter observations. //native/hermes/tests:supported_values_conformance_test repeats the comparison inside Hermes with real TS formatters and checks coercion, exception identity, function descriptors and fresh result arrays. Linux BuildBuddy builds/tests the SDK and cross-compiles the standalone consumer; macOS only runs its downloaded executable and bytecode.

Key coercion

Intl.supportedValuesOf converts its key to a string before validating the category. String wrapper objects are accepted; Symbols throw TypeError.

Intl.supportedValuesOf is callable but cannot be used as a constructor.

Time-zone candidates include the pinned IANA etcetera Zone records and UTC, in addition to continental transition zones. Runtime filtering retains primary identifiers and omits aliases such as Etc/UTC.

Collation enumeration probes CLDR-derived candidate locales for each type, including locale-specific collations such as German phonebk and Spanish trad. Only collations accepted by the installed Collator are returned.