format
PoolModern, comprehensive formatting library - bytes, numbers, currency, percentages, durations, and dates. Zero dependencies, TypeScript-first, tree-shakeable. 100% backward compatible with pretty-bytes.
dist
Functions
function formatBytes(bytes: number | bigint, options?: ByteFormatOptions): string
Convert bytes to a human readable string 100% backward compatible with pretty-bytes package
| Parameter | Type | Description |
|---|---|---|
bytes | number | bigint | - Number of bytes (or bigint) |
optionsoptional | ByteFormatOptions | - Formatting options |
function formatNumber(value: number | bigint, options?: NumberFormatOptions): string
Format a number with locale support Uses Intl.NumberFormat for zero-bundle-size internationalization
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | - Number to format |
optionsoptional | NumberFormatOptions | - Formatting options |
function formatCompact(value: number | bigint, options?: CompactFormatOptions): string
Format a number in compact notation Uses Intl.NumberFormat with compact notation
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | - Number to format |
optionsoptional | CompactFormatOptions | - Formatting options |
function formatCurrency(value: number | bigint, currency: string, options?: CurrencyFormatOptions): string
Format a number as currency Uses Intl.NumberFormat for currency formatting with locale support
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | - Amount to format |
currency | string | - Currency code (e.g., 'USD', 'EUR', 'GBP') |
optionsoptional | CurrencyFormatOptions | - Formatting options |
function formatPercent(value: number, options?: PercentFormatOptions): string
Format a number as percentage Uses Intl.NumberFormat for percentage formatting with locale support
| Parameter | Type | Description |
|---|---|---|
value | number | - Decimal value to format (e.g., 0.1234 for 12.34%) |
optionsoptional | PercentFormatOptions | - Formatting options |
function formatDuration(ms: number, options?: DurationFormatOptions): string
Format a duration (milliseconds) to human readable string Compatible with neo.ms patterns for consistency
| Parameter | Type | Description |
|---|---|---|
ms | number | - Duration in milliseconds |
optionsoptional | DurationFormatOptions | - Formatting options |
function formatDate(date: Date, style?: DateStyle | DateFormatOptions, options?: DateFormatOptions): string
Format a date to human readable string Uses Intl.DateTimeFormat for locale-aware formatting
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to format |
styleoptional | DateStyle | DateFormatOptions | - Preset style or custom options |
optionsoptional | DateFormatOptions | - Additional formatting options (when using preset) |
function formatRelative(value: number, unit: Intl.RelativeTimeFormatUnit, options?: RelativeTimeFormatOptions): string
Format relative time Uses Intl.RelativeTimeFormat for locale-aware relative time formatting
| Parameter | Type | Description |
|---|---|---|
value | number | - Numeric value for the unit |
unit | Intl.RelativeTimeFormatUnit | - Time unit (e.g., 'day', 'hour', 'minute') |
optionsoptional | RelativeTimeFormatOptions | - Formatting options |
function getCachedFormatter<T extends IntlFormatter>(key: string, factory: () => T): T
Get or create a cached Intl formatter
| Parameter | Type | Description |
|---|---|---|
key | string | - Cache key (should include all relevant options) |
factory | () => T | - Factory function to create the formatter |
function clearFormatterCache(): void
Clear the formatter cache (useful for testing)
function getFormatterCacheSize(): number
Get cache size (useful for monitoring)
Variables
readonly ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]Unit arrays for byte formatting Matches pretty-bytes exactly for 100% compatibility
readonly ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]readonly ["b", "kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"]readonly ["b", "kibit", "Mibit", "Gibit", "Tibit", "Pibit", "Eibit", "Zibit", "Yibit"]dist/bytes
Functions
function formatBytes(bytes: number | bigint, options?: ByteFormatOptions): string
Convert bytes to a human readable string 100% backward compatible with pretty-bytes package
| Parameter | Type | Description |
|---|---|---|
bytes | number | bigint | - Number of bytes (or bigint) |
optionsoptional | ByteFormatOptions | - Formatting options |
dist/bytes
Functions
function formatBytes(bytes: number | bigint, options?: ByteFormatOptions): string
Convert bytes to a human readable string 100% backward compatible with pretty-bytes package
| Parameter | Type | Description |
|---|---|---|
bytes | number | bigint | - Number of bytes (or bigint) |
optionsoptional | ByteFormatOptions | - Formatting options |
dist
Functions
function formatBytes(bytes: number | bigint, options?: ByteFormatOptions): string
Convert bytes to a human readable string 100% backward compatible with pretty-bytes package
| Parameter | Type | Description |
|---|---|---|
bytes | number | bigint | - Number of bytes (or bigint) |
optionsoptional | ByteFormatOptions | - Formatting options |
function formatNumber(value: number | bigint, options?: NumberFormatOptions): string
Format a number with locale support Uses Intl.NumberFormat for zero-bundle-size internationalization
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | - Number to format |
optionsoptional | NumberFormatOptions | - Formatting options |
function formatCompact(value: number | bigint, options?: CompactFormatOptions): string
Format a number in compact notation Uses Intl.NumberFormat with compact notation
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | - Number to format |
optionsoptional | CompactFormatOptions | - Formatting options |
function formatCurrency(value: number | bigint, currency: string, options?: CurrencyFormatOptions): string
Format a number as currency Uses Intl.NumberFormat for currency formatting with locale support
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | - Amount to format |
currency | string | - Currency code (e.g., 'USD', 'EUR', 'GBP') |
optionsoptional | CurrencyFormatOptions | - Formatting options |
function formatPercent(value: number, options?: PercentFormatOptions): string
Format a number as percentage Uses Intl.NumberFormat for percentage formatting with locale support
| Parameter | Type | Description |
|---|---|---|
value | number | - Decimal value to format (e.g., 0.1234 for 12.34%) |
optionsoptional | PercentFormatOptions | - Formatting options |
function formatDuration(ms: number, options?: DurationFormatOptions): string
Format a duration (milliseconds) to human readable string Compatible with neo.ms patterns for consistency
| Parameter | Type | Description |
|---|---|---|
ms | number | - Duration in milliseconds |
optionsoptional | DurationFormatOptions | - Formatting options |
function formatDate(date: Date, style?: DateStyle | DateFormatOptions, options?: DateFormatOptions): string
Format a date to human readable string Uses Intl.DateTimeFormat for locale-aware formatting
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to format |
styleoptional | DateStyle | DateFormatOptions | - Preset style or custom options |
optionsoptional | DateFormatOptions | - Additional formatting options (when using preset) |
function formatRelative(value: number, unit: Intl.RelativeTimeFormatUnit, options?: RelativeTimeFormatOptions): string
Format relative time Uses Intl.RelativeTimeFormat for locale-aware relative time formatting
| Parameter | Type | Description |
|---|---|---|
value | number | - Numeric value for the unit |
unit | Intl.RelativeTimeFormatUnit | - Time unit (e.g., 'day', 'hour', 'minute') |
optionsoptional | RelativeTimeFormatOptions | - Formatting options |
function getCachedFormatter<T extends IntlFormatter>(key: string, factory: () => T): T
Get or create a cached Intl formatter
| Parameter | Type | Description |
|---|---|---|
key | string | - Cache key (should include all relevant options) |
factory | () => T | - Factory function to create the formatter |
function clearFormatterCache(): void
Clear the formatter cache (useful for testing)
function getFormatterCacheSize(): number
Get cache size (useful for monitoring)
Variables
readonly ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]Unit arrays for byte formatting Matches pretty-bytes exactly for 100% compatibility
readonly ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]readonly ["b", "kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"]readonly ["b", "kibit", "Mibit", "Gibit", "Tibit", "Pibit", "Eibit", "Zibit", "Yibit"]Taxes calculated at checkout based on your location.