Const
The formatted address string
const address = {
street: "123 Main St",
city: "Springfield",
state: "IL",
zip: "62701"
};
const formatted = FormatUtils.formatAddress(address);
// "123 Main St, Springfield, IL, 62701"
The address object to format
Optional
street?: stringStreet address
Optional
city?: stringCity name
Optional
state?: stringState or province
Optional
zip?: stringZIP or postal code
Optional
country?: stringCountry name
Formats a credit card number by adding spaces every 4 digits.
The formatted card number with spaces
const card = FormatUtils.formatCreditCard("4111111111111111");
// "4111 1111 1111 1111"
The card number to format
Formats a number as currency using the Intl.NumberFormat API.
The formatted currency string
const price = FormatUtils.formatCurrency(99.99, "USD", "en-US");
// "$99.99"
const euros = FormatUtils.formatCurrency(99.99, "EUR", "de-DE");
// "99,99 €"
The amount to format
The currency code (e.g., 'USD', 'EUR', 'GBP')
The locale to use for formatting
Formats a file size in bytes to a human-readable string.
The formatted file size with appropriate unit
const size = FormatUtils.formatFileSize(1024); // "1 KB"
const size2 = FormatUtils.formatFileSize(1024 * 1024, 1); // "1.0 MB"
The size in bytes
Number of decimal places to show
Formats a number with commas as thousands separators.
Formatted number string with commas
const num = FormatUtils.formatNumber(1000000); // "1,000,000"
Number to format
Formats a number as a percentage.
The formatted percentage string
const percent = FormatUtils.formatPercent(75.5); // "75.5%"
The value to format
Number of decimal places to show
Formats a phone number according to the specified format.
The formatted phone number
const usPhone = FormatUtils.formatPhoneNumber("1234567890", "US");
// "(123) 456-7890"
const euPhone = FormatUtils.formatPhoneNumber("1234567890", "EU");
// "12 34 56 78 90"
The phone number to format
The format to use ('US' or 'EU')
Formats a duration in milliseconds to a human-readable string.
The formatted duration string
const short = FormatUtils.formatDuration(3661000, "short"); // "1h"
const long = FormatUtils.formatDuration(3661000, "long");
// "1 hour, 1 minute, 1 second"
The duration in milliseconds
The format to use ('short' or 'long')
Formats a social security number with hyphens.
The formatted SSN
const ssn = FormatUtils.formatSSN("123456789"); // "123-45-6789"
The SSN to format
Formats an address into a comma-separated string.