Search documentation

Search all pages, headings and text, in the current package or topic or in all documentation.

Errors and runtime

What the package throws, what it returns as empty, and which runtime capabilities two of its functions need.

@workspace/active-format 1.0.0Developmentunreleased, in development in Foundationbaseline ce081dc3

Three kinds of outcome#

SituationOutcome
an empty or unreadable value in a human formatter'': your interface decides what to show
a language tag the runtime cannot formatUnsupportedLocaleError
a programming or configuration errora RangeError (or Error) naming the problem

The package never falls back silently: there is no English floor and no host default.

Unsupported language tags#

Any BCP 47 tag your runtime's Intl formats is accepted. Every other tag throws an UnsupportedLocaleError, a RangeError that carries the locale as passed and a reason: malformed, unsupported, calendar (only the Gregorian calendar is supported) or numbering-system.

To test a tag before it becomes a presentation, for example a tag from a profile or a request header, use isSupportedLocale(tag). It gives the same verdict without throwing.

Unsupported language tagsClient

TagisSupportedLocaleformatNumber(1234.5)
en-GBtrue1,234.5
nltrue1.234,5
pt-BRtrue1.234,5
zz-ZZfalseUnsupportedLocaleError (unsupported)
en_USfalseUnsupportedLocaleError (malformed)
ja-JP-u-ca-japanesefalseUnsupportedLocaleError (calendar)

Configuration errors#

These throw, because they are mistakes in code or configuration, not in data:

  • a malformed pattern in formatDateWithPattern;
  • a malformed currency code, or an invalid decimals or sign;
  • an unknown unit in formatUnit;
  • an inconsistent NumberSpec, or one out of range;
  • smallestUnit larger than largestUnit in formatElapsedDuration;
  • an untyped call of todayIsoDate or calendarDayOf without a zone.

Runtime requirements#

The package installs no polyfill: your application owns its runtime. Two functions need an Intl capability beyond ES2022, in Node.js and in the browser alike:

FunctionNeedsWithout it
formatCurrency with a DecimalStringIntl.NumberFormat reading a string as an exact decimal (ES2023)silent precision loss: the engine converts the string to a number itself
formatElapsedDurationIntl.DurationFormat (ES2025)throws on every call

First versions with both, according to MDN's compatibility data: Chrome and Edge 129, Firefox 136, Safari 16.4, Node.js 23. Decide your supported runtimes from that, or check once at start-up:

TypeScript
const exactDecimal =  new Intl.NumberFormat('en', {useGrouping: false}).format(    '9007199254740993' as unknown as number,  ) === '9007199254740993';const elapsedDuration =  typeof (Intl as {DurationFormat?: unknown}).DurationFormat === 'function';

Without the exact-decimal capability, keep amounts with more digits than a double carries away from formatCurrency, or install a polyfill. Without Intl.DurationFormat, do not call formatElapsedDuration, or install a polyfill before the first call.

This page as Markdown