Change the language once. Every price and date follows.
formatCurrency(price, 'EUR') is one function over the platform's Intl. Read it in JSX and its text updates when the locale does, with no component re-rendering. The same call runs in plain code and on the server, and a /core entry with no dependencies carries it everywhere else.
bun add @pyreon/format - status
- ExperimentalThe API may change in a minor release before it is promoted to Stable.
- one call
setLocale('de')Every price, date and size in a binding rewrites its own text in place.- dates
- a calendar date never shifts
'2026-11-18'is the 18th in every time zone. - size
- 1.2 kB gzip for a number formatterFrom
/core, minified; @formatjs/intl is 13.1 kB for the same job. Date formatting is 2.7 kB.
- 1.2 kB gzip for one number formatter from
/core; @formatjs/intl needs 13.1 kB for the same jobpackages/fundamentals/format/bench/format-size.ts, "format a number", re-run 2026-11-18 on the merged tree: @pyreon/format/core 1,198 B, @formatjs/intl 13,107 B · Bun.build, minify, browser target, NODE_ENV=production, gzip, deterministic - 7.1 kB gzip for number, currency, bytes, duration, date, relative time and list together; @formatjs/intl with pretty-bytes and pretty-ms is 15.3 kBbench/format-size.ts, "the whole set": @pyreon/format/core 7,054 B, @formatjs/intl + pretty-bytes + pretty-ms 15,338 B · same build conditions
- 0 runtime dependencies in
/core: it imports no other package, and@pyreon/ambient,@pyreon/coreand@pyreon/reactivityserve only the reactive entrypackages/fundamentals/format/package.json; src/tests/entries.test.ts (no @pyreon import in /core)
synthetic · author-run · M3 Max · record of 2026-11-05
Every result, including where we lose →Every number in your app, in the reader's language.
One call switches everything
setLocale('de')and every formatted price, date and size on screen rewrites its own text node. Components do not re-render, and inputs keep their caret.One function per job
formatCurrency,formatBytes,formatDuration,formatList,formatRelativeTo. Plain data in, a string out: no classes, and no formatter object to build or pass around.Dates that stay put
A date string with no time is a calendar date: the same day in every zone, so
'2026-11-18'never becomes the 17th for someone in Los Angeles. An instant (Z, an offset, a number, aDate) is shown in the zone you pick.Parsing is the other half
parseNumber('1 234,5', { locale: 'cs' })is 1234.5,parseCurrency('€9.99', 'EUR')is 9.99 andparseDate('18. listopadu 2026', { locale: 'cs' })is'2026-11-18'. What the visitor typed in their own format, month names included, becomes a number or a date, and anything else isnull.
The locale stops being an argument.
The locale is a parameter of every call, a formatter is built each time, and a plain date string needs a UTC workaround.
const price = new Intl.NumberFormat(locale, { style: 'currency', currency: 'EUR' }).format(amount)
const day = new Intl.DateTimeFormat(locale, { dateStyle: 'long', timeZone: 'UTC' }).format(new Date('2026-11-18'))
// Change language: pass the new `locale` to every call and re-render everything that has one.The active locale is a signal. Each call reads it, so the text updates when it changes.
import { formatCurrency, formatDate, setLocale } from '@pyreon/format'
const Price = (props: { amount: number }) => <p>{formatCurrency(props.amount, 'EUR')}</p>
const Day = (props: { day: string }) => <p>{formatDate(props.day, 'long')}</p>
setLocale('de')
// <Price amount={1234.5} /> → "1.234,50 €"
// <Day day="2026-11-18" /> → "18. November 2026"Coming from Intl, pretty-bytes or @formatjs/intl?
The same strings, without building the formatter.
const price = new Intl.NumberFormat('de', { style: 'currency', currency: 'EUR' }).format(1234.5)
const day = new Intl.DateTimeFormat('de', { dateStyle: 'long', timeZone: 'UTC' }).format(new Date('2026-11-18'))
// "1.234,50 €", "18. November 2026"Checked against raw Intl for these two calls: the output is the same string, because Intl does the formatting. What changes is who builds and caches the formatter, and where the locale comes from. A calendar string needs no timeZone: 'UTC' workaround.
import { formatCurrency, formatDate, setLocale } from '@pyreon/format'
setLocale('de')
formatCurrency(1234.5, 'EUR') // "1.234,50 €"
formatDate('2026-11-18', 'long') // "18. November 2026"Sizes and durations in the reader's language.
import prettyBytes from 'pretty-bytes'
import prettyMs from 'pretty-ms'
prettyBytes(1536) // "1.54 kB"
prettyBytes(1536, { locale: 'de' }) // "1,54 kB"
prettyMs(3_905_000) // "1h 5m 5s"
prettyMs(3_905_000, { colonNotation: true }) // "1:05:05"pretty-bytes keeps three significant digits (1.54 kB); formatBytes shows one fraction digit (1.5 kB), and maximumFractionDigits changes it. pretty-ms prints English unit letters; formatDuration follows the locale's unit names. Both libraries are smaller for one job: pretty-ms is 1.2 kB gzip and formatDuration is 2.8 kB; pretty-bytes is 1.4 kB and formatBytes is 2.1 kB.
import { formatBytes, formatDuration } from '@pyreon/format'
formatBytes(1536) // "1.5 kB"
formatBytes(1536, { locale: 'de' }) // "1,5 kB"
formatDuration(3_905_000) // "1 hr, 5 min, 5 sec"
formatDuration(3_905_000, { style: 'digital' }) // "1:05:05"One active locale instead of an instance per locale.
import { createIntl } from '@formatjs/intl'
const intl = createIntl({ locale: 'de' })
intl.formatNumber(1234.5, { style: 'currency', currency: 'EUR' }) // "1.234,50 €"
intl.formatRelativeTime(-3, 'day') // "vor 3 Tagen"@formatjs/intl also formats ICU messages (plurals, selects); this package does not. Messages stay in @pyreon/i18n. For numbers, dates and relative time the output is the same strings, at 1.2 kB for a number against 13.1 kB gzip.
import { formatCurrency, formatRelative, setLocale } from '@pyreon/format'
setLocale('de')
formatCurrency(1234.5, 'EUR') // "1.234,50 €"
formatRelative(-3, 'day') // "vor 3 Tagen"Switch the language. Switch the zone. Everything moves.
One locale and one time zone drive every value below, through the real @pyreon/format. A price from cents is a formatter built with .from(), and the label that says how long ago something was posted ticks by itself. Type a number the way you would in that language and parseNumber reads it back. The calendar date stays on the 18th when the zone changes; the instant does not.
Price
€1,234.50Stored in cents
€1,234.56Audience
1.2MConversion
42.7%File size
7.3 MBSpeed
72 km/hDuration
1 hr, 5 min, 5 secList
Prague, Tokyo, and LimaCalendar date
November 18, 2026Date range
Nov 12 – 15, 2026Instant (follows the zone)
Nov 18, 2026, 11:30 PMWall-clock time (never shifts)
Nov 18, 2026, 2:30 PMRelative time
in 5 minutesPosted
–
parseNumber → 1234.5, printed back as 1,234.5
Try 1,234.5 or 1.234,5 or 1 234,5, then change the language.
provideLocale(() => lang())
provideTimeZone(() => zone())
// every row is one call, with no locale in sight
formatCurrency(1234.5, 'EUR')
formatDate('2026-11-18', 'long')
formatDateTime('2026-11-18T23:30:00Z')
const fromCents = currencyFormatter('EUR')
.from((c: number) => c / 100)
fromCents(123456)
<RelativeTime value={postedAt()} />
parseNumber(typed(), { locale: lang() })- localeen-US
- time zoneUTC
- row components that ran14
Two signals and two provide calls drive every value. Switch the language and each value rewrites its own text node; the row components do not run again.
Small functions, the whole job.
- Numbers, currency, percent
formatNumber,formatCurrencyandformatPercenttake the optionsIntlhas, plus presets for the common shapes. - Compact and units
formatCompact(1_240_000)is1.2M;formatUnit(72, 'kilometer-per-hour')is72 km/h. A unitIntldoes not have is a type error. - Bytes, decimal or binary
1.5 kBor, withbinary: true,1.5 KiB. Rounding never prints1000 kB: the value carries into the next unit. - Durations Milliseconds or
{ hours, minutes };largest: 2keeps the two biggest units,style: 'digital'gives1:05:05. UsesIntl.DurationFormatwhere it exists and an equivalent where it does not. - Lists
formatList(['red', 'green', 'blue'])joins the way the language does:and,or, or a plain unit list. - Dates and times
formatDate,formatTime,formatDateTimewithshorttofullpresets, or anyIntl.DateTimeFormatoptions. - Parsing, with month names
parseNumber,parseCurrencyandparseDateread what a visitor typed in their locale;parseDatereads18. listopadu 2026as well as18. 11. 2026. - Relative time and ranges
formatRelativeTo(target, base)picks the unit (yesterday,in 5 minutes);formatDateRangeandformatNumberRangecollapse the shared parts. - Formatters are values
currencyFormatter('EUR')returns a plain(value) => stringthat follows the locale. It drops intomap, a chart axis or a table column, and.with(),.from(),.range()and.fallback()derive new ones. - Named formats that extend
defineFormats({ price: { kind: 'currency', currency: 'EUR' }, priceShort: { extends: 'price', notation: 'compact' } }): each key is a real formatter, a typo inextendsis a type error. <Num>,<DateTime>,<RelativeTime><Num>renders reactive text with no wrapper;<DateTime>a real<time datetime>with atitle;<RelativeTime>a label that updates itself (3 minutes ago) and can switch to a date after a threshold.- Bounded caches, safe on data Each
Intlformatter is built once per locale and options, in tables with a size cap. Nullish input returns thefallbackand bad data never throws; a wrong option throws a[Pyreon]error that says how to fix it.
Things to build with it.
Name the formats once at module level. Each cell reads the active locale, so one setLocale rewrites the whole table.
import { defineFormats, setLocale } from '@pyreon/format'
import { Num } from '@pyreon/format/components'
const f = defineFormats({
price: { kind: 'currency', currency: 'EUR' },
size: { kind: 'bytes' },
})
const Row = (props: { name: string; price: number; bytes: number }) => (
<tr>
<td>{props.name}</td>
<td>{f.price(props.price)}</td>
<td><Num value={props.bytes} kind="bytes" /></td>
</tr>
)
// <Row name="Export" price={1234.5} bytes={1536} />
// en-US: "€1,234.50" "1.5 kB"
setLocale('de')
// de: "1.234,50 €" "1,5 kB"
setLocale('ja')
// ja: "€1,234.50" "1.5 KB"A calendar date stays on its day in every zone. An instant is shown in the zone you set. new Date('2026-11-18') is an instant at midnight UTC, so pass the string.
import { formatDate, formatDateTime, setTimeZone } from '@pyreon/format'
const birthday = '2026-11-18' // a calendar date
const standup = '2026-11-18T23:30:00Z' // an instant
setTimeZone('Asia/Tokyo')
formatDate(birthday) // "Nov 18, 2026"
formatDateTime(standup) // "Nov 19, 2026, 8:30 AM"
setTimeZone('America/Los_Angeles')
formatDate(birthday) // "Nov 18, 2026"
formatDateTime(standup) // "Nov 18, 2026, 3:30 PM"
formatDate(new Date(birthday)) // "Nov 17, 2026" ← the instant, not the dateParse with the locale the visitor types in. 1.234 is 1234 in German and 1.234 in English, so the locale is part of the question.
import { formatCurrency, parseNumber } from '@pyreon/format'
import { computed, signal } from '@pyreon/reactivity'
const typed = signal('1 234,5')
const amount = computed(() => parseNumber(typed(), { locale: 'cs' }))
// <input value={typed()} onInput={(e) => typed.set(e.currentTarget.value)} />
// <p>{() => (amount() === null ? 'Not a number' : formatCurrency(amount(), 'CZK', { locale: 'cs' }))}</p>
amount() // 1234.5 → "1 234,50 Kč"
parseNumber('1.234', { locale: 'de' }) // 1234
parseNumber('1.234', { locale: 'en-US' }) // 1.234
parseNumber('twelve', { locale: 'en-US' }) // nullBuild it once, derive variants, and hand it to anything that takes a callback. .from() adapts the input, so prices stored in cents need no division at the call site.
import { bytesFormatter, currencyFormatter, listFormatter, percentFormatter } from '@pyreon/format'
const price = currencyFormatter('EUR', { locale: 'en-US' })
price(9.99) // "€9.99"
price.range(10, 20) // "€10.00 – €20.00"
price.with({ maximumFractionDigits: 0 })(9.99) // "€10" (price itself is untouched)
const fromCents = price.from((cents: number) => cents / 100)
fromCents(999) // "€9.99"
;[999, 1250].map(fromCents) // ["€9.99", "€12.50"]
listFormatter({ locale: 'en-US' })([1250, 2500].map(fromCents)) // "€12.50 and €25.00"
const size = bytesFormatter({ locale: 'en-US' })
const pct = percentFormatter({ locale: 'en-US' })
`${size(1536)} of ${size(4096)} (${pct(1536 / 4096)})` // "1.5 kB of 4.1 kB (38%)"A named format can start from another by name. A typo is a type error and a cycle throws a [Pyreon] error.
import { defineFormats } from '@pyreon/format'
const f = defineFormats({
price: { kind: 'currency', currency: 'EUR', locale: 'en-US' },
priceShort: { extends: 'price', notation: 'compact' },
})
f.price(9.99) // "€9.99"
f.priceShort(1_234_567) // "€1.2M"
f.price.with({ currency: 'USD' })(9.99) // "$9.99"Plain functions and values, three entries.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- formatNumber
- formatCurrency
- formatPercent
- formatCompact
- formatUnit
- formatBytes
- formatDuration
- formatList
- formatDate
- formatTime
- formatDateTime
- formatRelative
- formatRelativeTo
- formatDateRange
- formatNumberRange
- formatNumberToParts
- formatDateToParts
- parseNumber
- parseCurrency
- parseDate
- numberFormatter
- currencyFormatter
- percentFormatter
- compactFormatter
- unitFormatter
- bytesFormatter
- durationFormatter
- listFormatter
- dateFormatter
- timeFormatter
- dateTimeFormatter
- relativeFormatter
- locale
- setLocale
- provideLocale
- timeZone
- setTimeZone
- provideTimeZone
- defineFormats
- createFormatter
- Num
- DateTime
- RelativeTime
- useRelativeTime
- @pyreon/format
- @pyreon/format/core
- @pyreon/format/components
Good to know before you start.
Experimental
The API may change in a minor release before it is promoted to Stable. Pin the version while you build on it, and read the changelog when you update.
A provided locale is visible in setup and effects
provideLocale is context. A formatter called in a component body, an effect, a computed or a JSX accessor sees it. One called from an event handler outside any scope sees the app default, so format in setup and keep the string if a handler needs it.
On the server, provide the locale per request
One process serves many requests, so setLocale does nothing there (and warns in development). Call provideLocale and provideTimeZone in the root component; they are request-scoped and never share a locale between requests.
Parsing covers numbers and numeric dates
parseDate reads numeric dates in the locale's order, ISO YYYY-MM-DD and the locale's own medium and long forms with month names. Compact notation (1.2M), scientific notation, natural language (next Friday), weekday names and times return null.
A relative label needs one line for server rendering
<RelativeTime> prints the request's clock on the server and starts no timer there. Render clockScript() from @pyreon/ambient in the page so the first client render reads the same instant, and the label hydrates without a mismatch.
Engines differ in CLDR data
Intl output is CLDR data, and V8, JavaScriptCore and ICU versions differ (a narrow no-break space before PM, for one). Pass the same locale and time zone on the server and in the browser; byte equality across engines is not promised.
iOS and Android are not covered yet
The package is web-only today. A core set of Intl number and date calls already lowers to the native targets without it; mapping these functions onto that set is planned, with no date.
What people ask first.
Does it work with @pyreon/i18n?
provideLocale takes an accessor, so provideLocale(() => i18n.locale()) makes every formatter follow an i18n instance's language today, and a test covers that seam. Having i18n's own n() and d() delegate to this package is planned, not shipped.
Where does the locale live?
In @pyreon/ambient, which holds the locale, the time zone and the clock and is re-exported here. @pyreon/time reads the same values, so one setLocale or setTimeZone changes everything that is formatted or counted. The Ambient docs page, linked below, covers pinning the clock for tests and the server hand-over.
Does it run on iOS and Android?
Not yet. The package is web-only. The native compiler already lowers a core set of Intl number and date formatting on its own; moving these functions onto it is planned, and we are not promising a date.
Is it fast?
We have not published speed numbers for it, so this page makes no speed claim. The design is to build each Intl formatter once per locale and options and reuse it, in bounded tables, so formatting in a list or a binding costs one format() call. The size figures above are measured.
Why not call Intl directly?
Call it directly when you format one value once. This package adds the cache, the active locale as a signal, presets, bytes and durations done right, calendar dates that do not shift, and parsing. A hand-written cache helper over Intl is much smaller (169 B gzip for one number, against 1.2 kB here) because it has no validation, presets, locale resolution, warnings or parsing.
Does a date really never shift with the time zone?
A string with no time (2026-11-18) or a date-time with no offset (2026-11-18T14:30) is a calendar value and shows that day or clock time in every zone. A string with Z or an offset, a number and a Date are instants and follow the zone. The one trap is new Date('2026-11-18'): that is an instant, midnight UTC.
What happens with bad data?
Nullish input returns the fallback (an empty string by default). Invalid input returns it too, with a warning in development. A programmer error, such as an unknown unit or a malformed locale tag handed to setLocale, throws a [Pyreon] error that says how to fix it.
Will the server and the browser print the same text?
When both get the same locale and time zone and run the same ICU data, yes. Engines can differ in small ways (a narrow no-break space before PM), so pass the locale and zone explicitly on both sides rather than relying on each side's default.
Built to be used together.
i18n
Translations and plurals. provideLocale(() => i18n.locale()) points every formatter at the same language.
Time
Dates as strings, zone math and clocks. Its values are the ones format prints.
Table
Sizes, prices and dates in cells, in the reader's format.
Ambient
The locale, time zone and clock that format and time share. It has no product page; its docs page covers it.
Say it the way they read it.
bun add @pyreon/format