/

  • Analyticsnpmv16.11.0

    • Overview
  • Apollonpmv15.2.1ESM

    • Overview
  • Browserslist-confignpmv15.2.1

    • Overview
  • CMSnpmv16.12.0

    • Overview
    • ContentBuilder
    • InviteUserForm
    • LoginForm
    • RenewPasswordForm
    • WysiwygInput
  • Corenpmv16.11.0

    • Overview
  • Core-Reactnpmv16.11.0

    • Overview
  • DataGridnpmv16.12.0

    • Overview
    • DataGrid
    • DataGridCustomExample
    • ExportButton
    • FilterList
    • Filters
    • FiltersButton
    • FulltextInput
    • HiddenColumns
    • HiddenColumnsButton
    • Pagination
    • RowCounts
    • RowsPerPageSelect
    • SelectedRowsToolbar
    • TableV2
    • ToolbarControl
    • ToolbarCustoms
    • ToolbarTabs
  • Datepickernpmv16.11.0

    • Overview
  • DnDnpmv16.11.0

    • Overview
  • E2E-Playwrightnpmv16.12.0

    • Overview
  • Eslint-confignpmv15.2.1

    • Overview
  • Formnpmv16.12.0

    • Overview
    • AvatarFileInput
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • ColorRadioGroup
    • Combobox
    • DatePickerInput
    • DateRangePickerInput
    • DatetimePickerInput
    • Dropzone
    • FileInput
    • Form
    • FormRenderer
    • GpsInput
    • MoneyInput
    • MultiCombobox
    • MultiSelect
    • NumberInput
    • PasswordInput
    • RadioGroup
    • Select
    • TextInput
    • Textarea
    • TimePickerInput
    • Toggle
  • Icons-generatornpmv16.11.0

    • Overview
  • Intlnpmv16.13.0

    • Overview
  • Localizenpmv16.11.0

    • Overview
  • Mailingnpmv16.10.0

    • Overview
  • Oxc-confignpmv16.11.0

    • Overview
  • Page-Buildernpmv15.3.0ESM

    • Overview
  • Page-Builder-CMSnpmv16.12.0ESM

    • Overview
  • Page-Builder-Webnpmv16.12.0ESM

    • Overview
  • Postcss-confignpmv16.8.0

    • Overview
  • Resizernpmv15.2.1

    • Overview
  • Routernpmv16.11.0ESM

    • Overview
  • Scriptsnpmv16.12.0

    • Overview
  • Sentrynpmv16.12.0ESM

    • Overview
  • Smart-addressnpmv15.2.1

    • Overview
  • Stylelint-confignpmv16.4.0

    • Overview
  • Stylesnpmv16.11.0

    • Overview
  • UInpmv16.12.0

    • Overview
    • Accordion
    • AlertBubble
    • AnnouncementBar
    • Avatar
    • AvatarFileInput
    • Badge
    • Button
    • ButtonGroup
    • ButtonList
    • Calendar
    • Checkbox
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • Chip
    • ColorRadio
    • ColorRadioGroup
    • Combobox
    • DatePicker
    • DatePickerInput
    • DateRangePicker
    • DateRangePickerInput
    • DatetimePicker
    • DatetimePickerInput
    • Dialog
    • Dropdown
    • Dropzone
    • ErrorMessage
    • FileInput
    • FlashMessages
    • FormComponent
    • Icon
    • IconButton
    • ImageGallery
    • InfoBox
    • Input
    • Label
    • Layout
    • Lightbox
    • ListItem
    • Loader
    • Lozenge
    • Menu
    • Message
    • Modal
    • ModalDialog
    • ModalHeader
    • MultiCombobox
    • MultiSelect
    • Pagination
    • Paper
    • Popover
    • Radio
    • RadioGroup
    • RasterImage
    • Select
    • Switch
    • Tabs
    • TextInput
    • TextLink
    • Textarea
    • TimePicker
    • TimePickerInput
    • Toggle
    • Tooltip
    • Typography
  • Wysiwygnpmv16.12.0

    • Overview
Previous← Icons-generator overviewNextLocalize overview →

@uxf/intl

npm

Locale-aware formatting of numbers, money, percentages, dates, times and relative time over the built-in Intl API. Pure functions without React; the only peer dependency is @uxf/core.

When to use

Use it wherever @uxf/localize cannot run: e-mail templates rendered by @uxf/mailing, Node scripts, API routes. The functions take the locale as their first argument and keep the call shape of @uxf/localize, so code reads the same in both places.

In a React app with a LocalizeProvider, keep using @uxf/localize for now.

Installation

yarn add @uxf/intl

Peer dependency (must be installed by the consumer): @uxf/core. intl takes its types (Money, DateValue, TimeString) and the small isNil/isNotNil helpers from it; a bundle gets only those modules of core.

Quick start

import { formatDateTime, formatMoney, formatNumber } from "@uxf/intl";

formatNumber("cs", 1234.5); // "1 235"
formatMoney("cs", { amount: "1234.5", currency: "CZK" }); // "1 235 Kč"
formatDateTime("cs", "2026-11-30T14:05:09+01:00", "dateTimeMedium"); // "30. 11. 2026 14:05"

The spaces around thousands, the currency and % are no-break spaces (U+00A0), as Intl returns them.

Functions

locale is any BCP 47 tag ("cs", "en", "de-AT"). Every Intl formatter is created once per locale and options and then reused, so calling the functions in a loop is cheap. Take the locale from a fixed set of the project's languages: the cache starts over once it holds 100 formatters, so locales taken straight from request headers only make it slower.

formatNumber(locale, value, options?)

OptionDefaultMeaning
precision0number of fraction digits, both minimum and maximum
showPlusSignfalse+ in front of a positive value; zero never gets a sign
formatNumber("cs", 1234.5, { precision: 2 }); // "1 234,50"
formatNumber("cs", 5, { showPlusSign: true }); // "+5"
formatNumber("cs", -0.4); // "0", never "-0"

formatMoney(locale, money, options?)

money is the Money of @uxf/core: { amount: string; currency: Currency }. The amount is formatted as the decimal string it is, so no digit is lost; an amount that is not a number throws RangeError. Options of formatNumber plus:

OptionDefaultMeaning
hideSymbolfalseonly the number, without the currency
preferIsoCodefalsethe ISO 4217 code (EUR) instead of the symbol
formatMoney("cs", { amount: "1234.5", currency: "EUR" }); // "1 235 €"
formatMoney("en", { amount: "1234.5", currency: "EUR" }); // "€1,235"
formatMoney("cs", { amount: "1234.5", currency: "EUR" }, { precision: 2, preferIsoCode: true }); // "1 234,50 EUR"

formatPercentage(locale, value, roundingType?, options?)

value is a fraction: 0.25 is 25 %. roundingType ("nearest", "up", "down" or null) rounds to whole percent before formatting; "nearest" rounds a half away from zero, as every function here does. Options are those of formatNumber.

formatPercentage("cs", 0.255); // "26 %"
formatPercentage("cs", 0.255, "down"); // "25 %"
formatPercentage("en", 0.255); // "26%"

formatDateTime(locale, value, format, timeZone = "Europe/Prague")

value is a Date, a date string (2026-11-30) or a date-time string with an offset (2026-11-30T14:05:09+01:00). format is a preset name or any Intl.DateTimeFormatOptions object.

formatDateTime("cs", "2026-11-30T14:05:09+01:00", "dateTimeLong"); // "30. listopadu 2026 v 14:05:09"
formatDateTime("cs", new Date("2026-07-01T10:00:00Z"), "timeShort"); // "12:00", summer time in Prague
formatDateTime("cs", "2026-11-30T14:05:09+01:00", { weekday: "long" }); // "pondělí"
formatDateTime("en", "2026-11-30T14:05:09+01:00", "timeShort", "America/New_York"); // "8:05 AM"
  • An instant is shown in timeZone, Prague by default, whatever zone the server runs in. A timeZone inside the options object takes precedence over the argument.
  • A date string without time is a calendar date, not an instant: 2026-03-29 prints as 29 March whatever zone is given, in the argument or in the options.
  • An invalid date (2026-02-30, nonsense) or an unknown preset name throws RangeError instead of printing Invalid Date.

Presets, the names of @uxf/localize, with 2026-11-30T14:05:09+01:00:

Presetcsen
timeShort14:052:05 PM
timeFull14:05:092:05:09 PM
dateShort30. 11. 2611/30/26
dateMedium30. 11. 202611/30/2026
dateLong30. listopadu 2026November 30, 2026
dateShortNoYear30. 11.11/30
dateLongNoYear30. listopaduNovember 30
dateTimeShort30. 11. 26 14:0511/30/26, 2:05 PM
dateTimeMedium30. 11. 2026 14:0511/30/2026, 2:05 PM
dateTimeLong30. listopadu 2026 v 14:05:09November 30, 2026 at 2:05:09 PM

DATE_TIME_PRESETS exports the Intl options behind each name, frozen, so spread them into a new object to adjust one.

formatTime(locale, value, format)

value is a time of day (14:30:00, the TimeString of @uxf/core). It has no date and no zone, so it is never shifted, not even by a timeZone in the options. format is "short", "long" or an Intl.DateTimeFormatOptions object; an object without any time field, such as { hourCycle: "h23" }, is added to "short".

formatTime("cs", "09:05:00", "short"); // "9:05"
formatTime("en", "14:30:00", "short"); // "2:30 PM"
formatTime("cs", "14:30:05", "long"); // "14:30:05"

formatRelativeTime(locale, value, unit, options?)

A thin wrapper over Intl.RelativeTimeFormat; value is negative for the past, options are passed through.

formatRelativeTime("cs", -3, "day"); // "před 3 dny"
formatRelativeTime("en", -3, "day"); // "3 days ago"
formatRelativeTime("cs", 1, "day", { numeric: "auto" }); // "zítra"

E-mail templates

A template of @uxf/mailing renders in Node, usually on a server in UTC. The functions show times in Prague unless told otherwise, so the e-mail says the same time as the web:

import type { DatetimeString } from "@uxf/core/date";
import type { Money } from "@uxf/core/money";
import { formatDateTime, formatMoney } from "@uxf/intl";
import { Text } from "react-email";

export function EmailComponent(props: { data: { startsAt: DatetimeString; price: Money } }) {
    return (
        <Text>
            Your appointment starts {formatDateTime("cs", props.data.startsAt, "dateTimeMedium")} and costs{" "}
            {formatMoney("cs", props.data.price)}.
        </Text>
    );
}

Differences from @uxf/localize

The output is what the runtime's ICU data returns, not a hand-written pattern, so some strings differ from @uxf/localize:

  • Czech date-times have no comma before the time (30. 11. 2026 14:05), and the long one joins them with v.
  • English long dates read November 30, 2026, and English date-times have a comma (11/30/2026, 2:05 PM).
  • English percentages have no space (26%).
  • Money uses the locale's own symbol and its placement (€1,235 in English, 1 235 £ in Czech) instead of the patterns configured in localize.
  • A negative half rounds away from zero: -1234.5 CZK prints -1 235 Kč.

A newer Node can change a string slightly when its ICU data changes; compare strings in tests with care.