Formatters
Helper functions for displaying data in human-readable formats.
Formatters transform data into user-friendly strings with proper locale support and opinionated defaults (Australian locale by default).
Display only
These formatters are intended for UI display purposes only. They apply rounding, truncation, and locale-specific transformations that make data human-readable but unsuitable for database storage or calculations.
Available Formatters
Byte
Format file sizes into human-readable strings.
Date
Date and time formatting utilities with locale-aware display and relative time formatting.
Duration
Format duration in seconds to human-readable time strings.
File
Format file types and extensions into human-readable strings.
Number
Format numbers with locale support, compact notation, percentages, and ordinals.
Currency
Format monetary values with proper symbols and locale support.
Name
Format person names with various display options.
Percentage
Format decimal values as percentage strings with null-safe handling.
Phone
Format and validate phone numbers with international support.
Text
Text manipulation utilities for truncation, pluralization, capitalization, and more.
Upload
Format upload progress, speed, and estimated time.
Usage
All formatters are available as named exports from @tilt-legal/cubitt-components:
import {
formatBytes,
formatCurrency,
formatDuration,
formatRelativeTime,
formatPhone,
} from "@tilt-legal/cubitt-components/utilities/formatters";
formatBytes(1048576); // "1 MB"
formatCurrency(1234.56); // "$1,234.56" (AUD)
formatDuration(154); // "2:34"
formatRelativeTime(new Date()); // "just now"
formatPhone("0412345678"); // "0412 345 678"