Format Styles Built-in and custom format styles for numbers, dates, times, and lists
pofile-ts extends ICU MessageFormat with 50+ built-in format styles and supports custom styles for full control over formatting. All styles use native Intl APIs — zero additional bundle size, full localization support.
English Deutsch Español
ICU MessageFormat uses the syntax {variable, type, style}:
import { compileIcu } from "pofile-ts"
// Basic: {variable, type}
compileIcu ( "{n, number}" , { locale: "en" })({ n: 1234.5 })
// → "1,234.5"
// With style: {variable, type, style}
compileIcu ( "{n, number, compact}" , { locale: "en" })({ n: 1500 })
// → "1.5K" Types available: number, date, time, list, plural, select, duration, ago, name
ICU MessageFormat nutzt die Syntax {variable, typ, stil}:
import { compileIcu } from "pofile-ts"
// Einfach: {variable, typ}
compileIcu ( "{n, number}" , { locale: "de" })({ n: 1234.5 })
// → "1.234,5"
// Mit Stil: {variable, typ, stil}
compileIcu ( "{n, number, compact}" , { locale: "de" })({ n: 1500 })
// → "1500" (oder "1,5 Tsd." je nach Browser) Verfügbare Typen: number, date, time, list, plural, select, duration, ago, name
ICU MessageFormat usa la sintaxis {variable, tipo, estilo}:
import { compileIcu } from "pofile-ts"
// Básico: {variable, tipo}
compileIcu ( "{n, number}" , { locale: "es" })({ n: 1234.5 })
// → "1.234,5"
// Con estilo: {variable, tipo, estilo}
compileIcu ( "{n, number, compact}" , { locale: "es" })({ n: 1500 })
// → "1,5 mil" Tipos disponibles: number, date, time, list, plural, select, duration, ago, name
These are part of the ICU MessageFormat specification:
Style Description Example (en) (default) Locale-aware decimal 1,234.5integerNo decimal places 1,235percentPercentage 42%currencyDynamic currency from values.currency $99.99
compileIcu ( "{rate, number, percent}" , { locale: "en" })({ rate: 0.42 })
// → "42%"
compileIcu ( "{price, number, currency}" , { locale: "en" })({ price: 99.99 , currency: "EUR" })
// → "€99.99"
English Deutsch Español
Perfect for dashboards, social media counts, and anywhere space is limited:
Style Description Example compactShort form (K, M, B) 1.5K, 2.5McompactLongLong form 1.5 thousand, 2.5 million
compileIcu ( "{followers, number, compact}" , { locale: "en" })({ followers: 2500000 })
// → "2.5M"
compileIcu ( "{views, number, compactLong}" , { locale: "en" })({ views: 1500 })
// → "1.5 thousand" Style Description Example decimal11 decimal place 3.1decimal22 decimal places 3.14decimal33 decimal places 3.142noGroupingNo thousand separators 1000000
compileIcu ( "{price, number, decimal2}" , { locale: "en" })({ price: 19.9 })
// → "19.90" Style Description Example signAlwaysAlways show +/- +5, -3signExceptZeroShow +/- except for 0 +5, 0, -3
compileIcu ( "{change, number, signAlways}" , { locale: "en" })({ change: 5 })
// → "+5" Perfekt für Dashboards, Social-Media-Zahlen und überall wo Platz begrenzt ist:
Stil Beschreibung Beispiel compactKurzform (Tsd., Mio.) 1,5 Tsd., 2,5 Mio.compactLongLangform 1,5 Tausend, 2,5 Millionen
compileIcu ( "{followers, number, compact}" , { locale: "de" })({ followers: 2500000 })
// → "2,5 Mio."
compileIcu ( "{views, number, compactLong}" , { locale: "de" })({ views: 1500 })
// → "1,5 Tausend" Stil Beschreibung Beispiel decimal11 Dezimalstelle 3,1decimal22 Dezimalstellen 3,14decimal33 Dezimalstellen 3,142noGroupingKeine Tausendertrennzeichen 1000000
compileIcu ( "{price, number, decimal2}" , { locale: "de" })({ price: 19.9 })
// → "19,90" Stil Beschreibung Beispiel signAlwaysImmer +/- anzeigen +5, -3signExceptZero+/- außer bei 0 +5, 0, -3
compileIcu ( "{change, number, signAlways}" , { locale: "de" })({ change: 5 })
// → "+5" Perfecto para dashboards, redes sociales y cualquier lugar con espacio limitado:
Estilo Descripción Ejemplo compactForma corta (mil, M) 1,5 mil, 2,5 McompactLongForma larga 1,5 mil, 2,5 millones
compileIcu ( "{followers, number, compact}" , { locale: "es" })({ followers: 2500000 })
// → "2,5 M"
compileIcu ( "{views, number, compactLong}" , { locale: "es" })({ views: 1500 })
// → "1,5 mil" Estilo Descripción Ejemplo decimal11 decimal 3,1decimal22 decimales 3,14decimal33 decimales 3,142noGroupingSin separadores de miles 1000000
compileIcu ( "{price, number, decimal2}" , { locale: "es" })({ price: 19.9 })
// → "19,90" Estilo Descripción Ejemplo signAlwaysSiempre mostrar +/- +5, -3signExceptZeroMostrar +/- excepto 0 +5, 0, -3
compileIcu ( "{change, number, signAlways}" , { locale: "es" })({ change: 5 })
// → "+5"
File Sizes Distance Temperature Weight/Volume Duration
Style Example (en) byte1,024 Bkilobyte512 kBmegabyte1.5 MBgigabyte2 GBterabyte1 TB
compileIcu ( "File size: {size, number, megabyte}" , { locale: "en" })({ size: 1.5 })
// → "File size: 1.5 MB" Style Example (en) meter100 mkilometer5 kmmile3 mi
compileIcu ( "Distance: {d, number, kilometer}" , { locale: "en" })({ d: 42.195 })
// → "Distance: 42.195 km" Style Example (en) celsius22°Cfahrenheit72°F
compileIcu ( "Temperature: {temp, number, celsius}" , { locale: "en" })({ temp: 22 })
// → "Temperature: 22°C" Style Example (en) kilogram70 kggram500 gpound154 lbliter1.5 Lmilliliter250 mL
compileIcu ( "Weight: {w, number, kilogram}" , { locale: "en" })({ w: 70 })
// → "Weight: 70 kg" Style Example (en) second30 secminute5 minhour2 hrday3 daysweek2 wkmonth6 moyear1 yr
compileIcu ( "Duration: {t, number, minute}" , { locale: "en" })({ t: 45 })
// → "Duration: 45 min"
Style Example (en) Example (de) (default) Dec 15, 202415.12.2024short12/15/2415.12.24mediumDec 15, 202415.12.2024longDecember 15, 202415. Dezember 2024fullSunday, December 15, 2024Sonntag, 15. Dezember 2024
English Deutsch Español
Style Description Example isoISO-like format 12/15/2024weekdayWeekday only SundayweekdayShortShort weekday SunmonthYearMonth and year December 2024monthYearShortShort month and year Dec 2024monthDayMonth and day Dec 15monthDayLongLong month and day December 15dayMonthDay and month 15 DecdayMonthYearDay, month, year Dec 15, 2024weekdayMonthDayWeekday, month, day Sunday, December 15
compileIcu ( "Published: {d, date, monthYear}" , { locale: "en" })({ d: new Date ( 2024 , 11 , 15 ) })
// → "Published: December 2024"
compileIcu ( "Today is {d, date, weekday}" , { locale: "en" })({ d: new Date () })
// → "Today is Monday" Stil Beschreibung Beispiel isoISO-ähnliches Format 15.12.2024weekdayNur Wochentag SonntagweekdayShortKurzer Wochentag SomonthYearMonat und Jahr Dezember 2024monthYearShortKurzer Monat und Jahr Dez. 2024monthDayMonat und Tag 15. Dez.monthDayLongLanger Monat und Tag 15. DezemberdayMonthTag und Monat 15. Dez.dayMonthYearTag, Monat, Jahr 15. Dez. 2024weekdayMonthDayWochentag, Monat, Tag Sonntag, 15. Dezember
compileIcu ( "Veröffentlicht: {d, date, monthYear}" , { locale: "de" })({ d: new Date ( 2024 , 11 , 15 ) })
// → "Veröffentlicht: Dezember 2024"
compileIcu ( "Heute ist {d, date, weekday}" , { locale: "de" })({ d: new Date () })
// → "Heute ist Montag" Estilo Descripción Ejemplo isoFormato tipo ISO 15/12/2024weekdaySolo día de la semana domingoweekdayShortDía corto dommonthYearMes y año diciembre de 2024monthYearShortMes corto y año dic 2024monthDayMes y día 15 dicmonthDayLongMes largo y día 15 de diciembredayMonthDía y mes 15 dicdayMonthYearDía, mes, año 15 dic 2024weekdayMonthDayDía semana, mes, día domingo, 15 de diciembre
compileIcu ( "Publicado: {d, date, monthYear}" , { locale: "es" })({ d: new Date ( 2024 , 11 , 15 ) })
// → "Publicado: diciembre de 2024"
compileIcu ( "Hoy es {d, date, weekday}" , { locale: "es" })({ d: new Date () })
// → "Hoy es lunes"
Style Example (en) Example (de) (default) 2:30:00 PM14:30:00short2:30 PM14:30medium2:30:00 PM14:30:00long2:30:00 PM GMT+114:30:00 MEZfull2:30:00 PM Central European Time14:30:00 Mitteleuropäische Zeit
Style Description Example (en) hourMinuteHH:MM 14:30hourMinute1212-hour format 2:30 PMhourMinute2424-hour format 14:30hourMinuteSecondHH:MM:SS 14:30:45hourMinuteSecond1212-hour with seconds 2:30:45 PMhourMinuteSecond2424-hour with seconds 14:30:45hourHour only 2 PMhour1212-hour 2 PMhour2424-hour 14
compileIcu ( "Meeting at {t, time, hourMinute24}" , { locale: "en" })({ t: new Date () })
// → "Meeting at 14:30"
compileIcu ( "Alarm: {t, time, hour12}" , { locale: "en" })({ t: new Date ( 2024 , 0 , 1 , 7 , 0 ) })
// → "Alarm: 7 AM"
Style Description Example (en) (default) Conjunction (and) A, B, and CconjunctionConjunction (and) A, B, and CdisjunctionDisjunction (or) A, B, or CunitUnit list (no connector) A, B, C
Style Description Example (en) orAlias for disjunction A, B, or CshortShort conjunction A, B, & CnarrowNarrow (minimal) A, B, CorShortShort disjunction A, B, or CorNarrowNarrow disjunction A, B, or CunitShortShort unit A, B, CunitNarrowNarrow unit A B C
English Deutsch Español
compileIcu ( "Choose: {options, list, or}" , { locale: "en" })({ options: [ "red" , "blue" , "green" ] })
// → "Choose: red, blue, or green"
compileIcu ( "Authors: {names, list}" , { locale: "en" })({ names: [ "Alice" , "Bob" , "Charlie" ] })
// → "Authors: Alice, Bob, and Charlie"
compileIcu ( "Tags: {tags, list, narrow}" , { locale: "en" })({
tags: [ "react" , "typescript" , "vite" ]
})
// → "Tags: react, typescript, vite" compileIcu ( "Wähle: {options, list, or}" , { locale: "de" })({ options: [ "rot" , "blau" , "grün" ] })
// → "Wähle: rot, blau oder grün"
compileIcu ( "Autoren: {names, list}" , { locale: "de" })({ names: [ "Alice" , "Bob" , "Charlie" ] })
// → "Autoren: Alice, Bob und Charlie"
compileIcu ( "Tags: {tags, list, narrow}" , { locale: "de" })({
tags: [ "react" , "typescript" , "vite" ]
})
// → "Tags: react, typescript, vite" compileIcu ( "Elige: {options, list, or}" , { locale: "es" })({ options: [ "rojo" , "azul" , "verde" ] })
// → "Elige: rojo, azul o verde"
compileIcu ( "Autores: {names, list}" , { locale: "es" })({ names: [ "Alice" , "Bob" , "Charlie" ] })
// → "Autores: Alice, Bob y Charlie"
compileIcu ( "Tags: {tags, list, narrow}" , { locale: "es" })({
tags: [ "react" , "typescript" , "vite" ]
})
// → "Tags: react, typescript, vite"
When built-in styles aren't enough, define your own with full Intl API options:
English Deutsch Español
import { compileIcu } from "pofile-ts"
const fn = compileIcu ( "{amount, number, priceEur}" , {
locale: "en" ,
numberStyles: {
priceEur: {
style: "currency" ,
currency: "EUR" ,
minimumFractionDigits: 2
}
}
})
fn ({ amount: 1234.5 })
// → "€1,234.50" Option Intl API Example Options numberStylesIntl.NumberFormatstyle, currency, notation, minimumFractionDigits, unit, etc.dateStylesIntl.DateTimeFormatweekday, year, month, day, era, etc.timeStylesIntl.DateTimeFormathour, minute, second, hour12, timeZone, etc.listStylesIntl.ListFormattype, style
const compile = createIcuCompiler ({
locale: "en" ,
numberStyles: {
// Scientific notation for large numbers
scientific: { notation: "scientific" },
// Accounting format (negative in parentheses)
accounting: { style: "currency" , currency: "USD" , currencySign: "accounting" },
// Speed in km/h
speed: { style: "unit" , unit: "kilometer-per-hour" }
},
dateStyles: {
// Quarter + Year
quarter: { year: "numeric" , month: "long" },
// Relative date context
relative: { weekday: "long" , month: "short" , day: "numeric" }
}
}) import { compileIcu } from "pofile-ts"
const fn = compileIcu ( "{amount, number, preisEur}" , {
locale: "de" ,
numberStyles: {
preisEur: {
style: "currency" ,
currency: "EUR" ,
minimumFractionDigits: 2
}
}
})
fn ({ amount: 1234.5 })
// → "1.234,50 €" Option Intl API Beispiel-Optionen numberStylesIntl.NumberFormatstyle, currency, notation, minimumFractionDigits, unit, etc.dateStylesIntl.DateTimeFormatweekday, year, month, day, era, etc.timeStylesIntl.DateTimeFormathour, minute, second, hour12, timeZone, etc.listStylesIntl.ListFormattype, style
const compile = createIcuCompiler ({
locale: "de" ,
numberStyles: {
// Wissenschaftliche Notation für große Zahlen
wissenschaftlich: { notation: "scientific" },
// Buchhaltungsformat (negativ in Klammern)
buchhaltung: { style: "currency" , currency: "EUR" , currencySign: "accounting" },
// Geschwindigkeit in km/h
geschwindigkeit: { style: "unit" , unit: "kilometer-per-hour" }
},
dateStyles: {
// Quartal + Jahr
quartal: { year: "numeric" , month: "long" },
// Relativer Datumskontext
relativ: { weekday: "long" , month: "short" , day: "numeric" }
}
}) import { compileIcu } from "pofile-ts"
const fn = compileIcu ( "{amount, number, precioEur}" , {
locale: "es" ,
numberStyles: {
precioEur: {
style: "currency" ,
currency: "EUR" ,
minimumFractionDigits: 2
}
}
})
fn ({ amount: 1234.5 })
// → "1.234,50 €" Opción Intl API Opciones de Ejemplo numberStylesIntl.NumberFormatstyle, currency, notation, minimumFractionDigits, unit, etc.dateStylesIntl.DateTimeFormatweekday, year, month, day, era, etc.timeStylesIntl.DateTimeFormathour, minute, second, hour12, timeZone, etc.listStylesIntl.ListFormattype, style
const compile = createIcuCompiler ({
locale: "es" ,
numberStyles: {
// Notación científica para números grandes
cientifico: { notation: "scientific" },
// Formato contable (negativo entre paréntesis)
contable: { style: "currency" , currency: "EUR" , currencySign: "accounting" },
// Velocidad en km/h
velocidad: { style: "unit" , unit: "kilometer-per-hour" }
},
dateStyles: {
// Trimestre + Año
trimestre: { year: "numeric" , month: "long" },
// Contexto de fecha relativa
relativo: { weekday: "long" , month: "short" , day: "numeric" }
}
})
For real-world apps, use createIcuCompiler to define styles once and reuse everywhere:
import { createIcuCompiler } from "pofile-ts"
// Define once in your i18n config (e.g., src/i18n/compiler.ts)
export const compile = createIcuCompiler ({
locale: "en" ,
numberStyles: {
bytes: { style: "unit" , unit: "byte" , unitDisplay: "narrow" },
filesize: { style: "unit" , unit: "kilobyte" , unitDisplay: "short" },
percent2: { style: "percent" , minimumFractionDigits: 2 }
},
dateStyles: {
iso: { year: "numeric" , month: "2-digit" , day: "2-digit" },
monthYear: { month: "long" , year: "numeric" }
},
timeStyles: {
clock: { hour: "2-digit" , minute: "2-digit" , hour12: false }
}
})
// Use everywhere in your app
const sizeMsg = compile ( "{size, number, bytes}" )
const dateMsg = compile ( "{d, date, iso}" )
const timeMsg = compile ( "{t, time, clock}" )
sizeMsg ({ size: 1024 }) // → "1,024B"
dateMsg ({ d: new Date () }) // → "12/16/2024"
timeMsg ({ t: new Date () }) // → "14:30"
Benefits:
DRY — Styles defined once, no repetition
Testable — Inject different configs for tests
SSR-safe — No global state, each request can have its own compiler
Tree-shakeable — Only included in bundle when used
For apps where currency varies per user or transaction:
compileIcu ( "{price, number, currency}" , { locale: "en" })({
price: 99.99 ,
currency: "EUR" // Read from values at runtime
})
// → "€99.99"
The currency is:
Read from values.currency at runtime
Cached per currency for performance
Falls back to USD if not provided
Category Type Styles Standard ICU number integer, percent, currencyStandard ICU date/time short, medium, long, fullStandard ICU list conjunction, disjunction, unitpofile-ts Built-in number compact, compactLong, decimal1-3, signAlways, signExceptZero, noGroupingpofile-ts Built-in number (units) byte, kilobyte, megabyte, gigabyte, terabyte, meter, kilometer, mile, celsius, fahrenheit, kilogram, gram, pound, liter, milliliter, second, minute, hour, day, week, month, yearpofile-ts Built-in date iso, weekday, weekdayShort, monthYear, monthYearShort, monthDay, monthDayLong, dayMonth, dayMonthYear, weekdayMonthDaypofile-ts Built-in time hourMinute, hourMinute12, hourMinute24, hourMinuteSecond, hourMinuteSecond12, hourMinuteSecond24, hour, hour12, hour24pofile-ts Built-in list or, short, narrow, orShort, orNarrow, unitShort, unitNarrowCustom all Any Intl options via numberStyles, dateStyles, timeStyles, listStyles