Neo Zero

format

Pool

Modern, comprehensive formatting library - bytes, numbers, currency, percentages, durations, and dates. Zero dependencies, TypeScript-first, tree-shakeable. 100% backward compatible with pretty-bytes.

$ lpm install @lpm.dev/neo.format
32 exportsTypeScript

dist

Functions

formatBytes
function formatBytes(bytes: number | bigint, options?: ByteFormatOptions): string

Convert bytes to a human readable string 100% backward compatible with pretty-bytes package

ParameterTypeDescription
bytes
number | bigint- Number of bytes (or bigint)
optionsoptional
ByteFormatOptions- Formatting options
formatNumber
function formatNumber(value: number | bigint, options?: NumberFormatOptions): string

Format a number with locale support Uses Intl.NumberFormat for zero-bundle-size internationalization

ParameterTypeDescription
value
number | bigint- Number to format
optionsoptional
NumberFormatOptions- Formatting options
formatCompact
function formatCompact(value: number | bigint, options?: CompactFormatOptions): string

Format a number in compact notation Uses Intl.NumberFormat with compact notation

ParameterTypeDescription
value
number | bigint- Number to format
optionsoptional
CompactFormatOptions- Formatting options
formatCurrency
function formatCurrency(value: number | bigint, currency: string, options?: CurrencyFormatOptions): string

Format a number as currency Uses Intl.NumberFormat for currency formatting with locale support

ParameterTypeDescription
value
number | bigint- Amount to format
currency
string- Currency code (e.g., 'USD', 'EUR', 'GBP')
optionsoptional
CurrencyFormatOptions- Formatting options
formatPercent
function formatPercent(value: number, options?: PercentFormatOptions): string

Format a number as percentage Uses Intl.NumberFormat for percentage formatting with locale support

ParameterTypeDescription
value
number- Decimal value to format (e.g., 0.1234 for 12.34%)
optionsoptional
PercentFormatOptions- Formatting options
formatDuration
function formatDuration(ms: number, options?: DurationFormatOptions): string

Format a duration (milliseconds) to human readable string Compatible with neo.ms patterns for consistency

ParameterTypeDescription
ms
number- Duration in milliseconds
optionsoptional
DurationFormatOptions- Formatting options
formatDate
function formatDate(date: Date, style?: DateStyle | DateFormatOptions, options?: DateFormatOptions): string

Format a date to human readable string Uses Intl.DateTimeFormat for locale-aware formatting

ParameterTypeDescription
date
Date- Date to format
styleoptional
DateStyle | DateFormatOptions- Preset style or custom options
optionsoptional
DateFormatOptions- Additional formatting options (when using preset)
formatRelative
function formatRelative(value: number, unit: Intl.RelativeTimeFormatUnit, options?: RelativeTimeFormatOptions): string

Format relative time Uses Intl.RelativeTimeFormat for locale-aware relative time formatting

ParameterTypeDescription
value
number- Numeric value for the unit
unit
Intl.RelativeTimeFormatUnit- Time unit (e.g., 'day', 'hour', 'minute')
optionsoptional
RelativeTimeFormatOptions- Formatting options
getCachedFormatter
function getCachedFormatter<T extends IntlFormatter>(key: string, factory: () => T): T

Get or create a cached Intl formatter

ParameterTypeDescription
key
string- Cache key (should include all relevant options)
factory
() => T- Factory function to create the formatter
clearFormatterCache
function clearFormatterCache(): void

Clear the formatter cache (useful for testing)

getFormatterCacheSize
function getFormatterCacheSize(): number

Get cache size (useful for monitoring)

Variables

BYTE_UNITSreadonly ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]

Unit arrays for byte formatting Matches pretty-bytes exactly for 100% compatibility

BIBYTE_UNITSreadonly ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
BIT_UNITSreadonly ["b", "kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"]
BIBIT_UNITSreadonly ["b", "kibit", "Mibit", "Gibit", "Tibit", "Pibit", "Eibit", "Zibit", "Yibit"]

dist/bytes

Functions

formatBytes
function formatBytes(bytes: number | bigint, options?: ByteFormatOptions): string

Convert bytes to a human readable string 100% backward compatible with pretty-bytes package

ParameterTypeDescription
bytes
number | bigint- Number of bytes (or bigint)
optionsoptional
ByteFormatOptions- Formatting options

dist/bytes

Functions

formatBytes
function formatBytes(bytes: number | bigint, options?: ByteFormatOptions): string

Convert bytes to a human readable string 100% backward compatible with pretty-bytes package

ParameterTypeDescription
bytes
number | bigint- Number of bytes (or bigint)
optionsoptional
ByteFormatOptions- Formatting options

dist

Functions

formatBytes
function formatBytes(bytes: number | bigint, options?: ByteFormatOptions): string

Convert bytes to a human readable string 100% backward compatible with pretty-bytes package

ParameterTypeDescription
bytes
number | bigint- Number of bytes (or bigint)
optionsoptional
ByteFormatOptions- Formatting options
formatNumber
function formatNumber(value: number | bigint, options?: NumberFormatOptions): string

Format a number with locale support Uses Intl.NumberFormat for zero-bundle-size internationalization

ParameterTypeDescription
value
number | bigint- Number to format
optionsoptional
NumberFormatOptions- Formatting options
formatCompact
function formatCompact(value: number | bigint, options?: CompactFormatOptions): string

Format a number in compact notation Uses Intl.NumberFormat with compact notation

ParameterTypeDescription
value
number | bigint- Number to format
optionsoptional
CompactFormatOptions- Formatting options
formatCurrency
function formatCurrency(value: number | bigint, currency: string, options?: CurrencyFormatOptions): string

Format a number as currency Uses Intl.NumberFormat for currency formatting with locale support

ParameterTypeDescription
value
number | bigint- Amount to format
currency
string- Currency code (e.g., 'USD', 'EUR', 'GBP')
optionsoptional
CurrencyFormatOptions- Formatting options
formatPercent
function formatPercent(value: number, options?: PercentFormatOptions): string

Format a number as percentage Uses Intl.NumberFormat for percentage formatting with locale support

ParameterTypeDescription
value
number- Decimal value to format (e.g., 0.1234 for 12.34%)
optionsoptional
PercentFormatOptions- Formatting options
formatDuration
function formatDuration(ms: number, options?: DurationFormatOptions): string

Format a duration (milliseconds) to human readable string Compatible with neo.ms patterns for consistency

ParameterTypeDescription
ms
number- Duration in milliseconds
optionsoptional
DurationFormatOptions- Formatting options
formatDate
function formatDate(date: Date, style?: DateStyle | DateFormatOptions, options?: DateFormatOptions): string

Format a date to human readable string Uses Intl.DateTimeFormat for locale-aware formatting

ParameterTypeDescription
date
Date- Date to format
styleoptional
DateStyle | DateFormatOptions- Preset style or custom options
optionsoptional
DateFormatOptions- Additional formatting options (when using preset)
formatRelative
function formatRelative(value: number, unit: Intl.RelativeTimeFormatUnit, options?: RelativeTimeFormatOptions): string

Format relative time Uses Intl.RelativeTimeFormat for locale-aware relative time formatting

ParameterTypeDescription
value
number- Numeric value for the unit
unit
Intl.RelativeTimeFormatUnit- Time unit (e.g., 'day', 'hour', 'minute')
optionsoptional
RelativeTimeFormatOptions- Formatting options
getCachedFormatter
function getCachedFormatter<T extends IntlFormatter>(key: string, factory: () => T): T

Get or create a cached Intl formatter

ParameterTypeDescription
key
string- Cache key (should include all relevant options)
factory
() => T- Factory function to create the formatter
clearFormatterCache
function clearFormatterCache(): void

Clear the formatter cache (useful for testing)

getFormatterCacheSize
function getFormatterCacheSize(): number

Get cache size (useful for monitoring)

Variables

BYTE_UNITSreadonly ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]

Unit arrays for byte formatting Matches pretty-bytes exactly for 100% compatibility

BIBYTE_UNITSreadonly ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
BIT_UNITSreadonly ["b", "kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"]
BIBIT_UNITSreadonly ["b", "kibit", "Mibit", "Gibit", "Tibit", "Pibit", "Eibit", "Zibit", "Yibit"]
Unlimited AccessInstall as many Pool packages as you need.
Fund Real WorkEvery install you run sends revenue directly to the developer who built it.

Taxes calculated at checkout based on your location.

Weekly Installs
3
Version
1.0.0
Published
LicenseMIT
Size191.81 KB
Files19
Node version>= 18
TypeScriptYes