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.
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.
yarn add @uxf/intlPeer 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.
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.
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?)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:
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"
timeZone, Prague by default, whatever zone the server runs in. A timeZone inside the
options object takes precedence over the argument.2026-03-29 prints as 29 March whatever zone is
given, in the argument or in the options.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:
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"
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>
);
}
@uxf/localizeThe output is what the runtime's ICU data returns, not a hand-written pattern, so some strings differ from
@uxf/localize:
30. 11. 2026 14:05), and the long one joins them with v.November 30, 2026, and English date-times have a comma (11/30/2026, 2:05 PM).26%).€1,235 in English, 1 235 £ in Czech) instead of the
patterns configured in localize.-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.