Formatting
Format dates, numbers, currencies, and strings.
Formatting Utilities
Formatting utilities use the native Intl API for locale-aware formatting of dates, numbers, and currencies.
Currency
import { formatCurrency } from '@/lib/utils';
formatCurrency(1234.56); // "$1,234.56"
formatCurrency(1234.56, 'EUR'); // "€1,234.56"
formatCurrency(1234.56, 'JPY', 'ja-JP'); // "¥1,235"
Numbers
import { formatNumber } from '@/lib/utils';
formatNumber(1234567); // "1,234,567"
formatNumber(1234567, 'de-DE'); // "1.234.567"
Dates
import { formatDate } from '@/lib/utils';
formatDate(new Date());
// "December 11, 2025"
formatDate(new Date(), {
year: 'numeric',
month: 'short',
day: 'numeric'
});
// "Dec 11, 2025"
formatDate('2025-01-15', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
// "Wednesday, January 15, 2025"
Relative Time
import { formatRelativeTime } from '@/lib/utils';
formatRelativeTime(Date.now() - 3600000); // "1 hour ago"
formatRelativeTime(Date.now() + 86400000); // "tomorrow"
formatRelativeTime(Date.now() - 60000); // "1 minute ago"
Strings
import { truncate, capitalize, slugify } from '@/lib/utils';
truncate('Long text here', 10); // "Long text..."
capitalize('hello'); // "Hello"
slugify('Hello World!'); // "hello-world"
API Reference
| Function | Parameters | Returns |
|---|---|---|
formatCurrency | amount, currency?, locale? | string |
formatNumber | value, locale? | string |
formatDate | date, options?, locale? | string |
formatRelativeTime | date, locale? | string |
truncate | str, length | string |
capitalize | str | string |
slugify | str | string |