Docs
/
formatters

Formatters

Wrangle wild data types into submission. Spruce up numbers, give strings smarts, and make complex content dazzle.

formatNumber

Link Copied!

Format numbers into neat and formatted strings for people

formatNumber(12345.1242, { decimals: 1, locale: en-US })
12,345.1
Result
formatNumber(number: number, options?: { decimals?: number; locale?: string })

formatCurrency

Link Copied!

Format numbers into local currency with extra smarts

formatCurrency(0.000009876, { decimals: 7, locale: en-US })
$0.0000099
Result
formatCurrency(number: number, options?: { decimals?: number; locale?: string })

formatValuation

Link Copied!

Format numbers into valuations displayed in thousands, millions or billions

formatValuation(12345678910, { decimals: 0, locale: en-US })
$12B
Result
formatValuation(number: number, options?: { decimals?: number; locale?: string })

formatUnit

Link Copied!

Format a number into a your unit of choice

formatUnit(0.12, { unit: acre, unitDisplay: long, locale: en-US })
0.12 acres
Result
formatUnit(number: number, options: { unit: string; decimals?: number; unitDisplay?: 'short' | 'long'; locale?: string })

formatPercentage

Link Copied!

Format a number into a percentage

formatPercentage(0.12, { decimals: 0, locale: en-US })
12%
Result
formatPercentage(number: number, options?: { decimals?: number; locale?: string })

formatDurationLabels

Link Copied!

Format time into a human-readable string

formatDurationLabels(954321, { labels: 'long', round: false })
11 days 1 hour 5 minutes 21 seconds
Result
formatDurationLabels(seconds: number, options?: { labels?: 'short' | 'long'; round?: boolean })

formatDurationNumbers

Link Copied!

Format time into duration 00:00:00

formatDurationNumbers(987)
00:16:27
Result
formatDurationNumbers(seconds: number)

formatFileSize

Link Copied!

Format and auto calculate file size into human-readable string

formatFileSize(1024, { inputUnit: byte, unitDisplay: short, })
1 kB
Result
formatFileSize(number: number, options?: { decimals?: number; inputUnit?: string; outputUnit?: string; unitDisplay?: 'short' | 'long'; locale?: string })

formatLength

Link Copied!

Format and auto calculate length into human-readable string

formatLength(1500, { inputUnit: millimeter, unitDisplay: short, })
1.5 m
Result
formatLength(number: number, options?: { decimals?: number; inputUnit?: string; outputUnit?: string; unitDisplay?: 'short' | 'long'; locale?: string })

formatTemperature

Link Copied!

Format and auto calculate temperature into human-readable string

formatTemperature(32, { inputUnit: celsius, unitDisplay: short, })
32°C
Result
formatTemperature(number: number, options?: { decimals?: number; inputUnit?: string; outputUnit?: string; unitDisplay?: 'short' | 'long'; locale?: string })

formatNumberToWords

Link Copied!

Format numbers into words

formatNumberToWords(1234567)
one million, two hundred and thirty-four thousand, five hundred and sixty-seven
Result
formatNumberToWords(number: number)

formatParagraphs

Link Copied!

Formats content into paragraphs with a minimum number of characters per sentence and minimum number of sentences per paragraph

formatParagraphs('all-your-long-text', { minCharacterCount: 80, minSentenceCount: 2 })
A scooter (motor scooter) is a motorcycle with an underbone or step-through frame, a seat, a transmission that shifts without the operator having to operate a clutch lever, a platform for their feet, and with a method of operation that emphasizes comfort and fuel economy. Elements of scooter design were present in some of the earliest motorcycles, and motor scooters have been made since at least 1914. More recently, scooters have evolved to include scooters exceeding 250cc classified as Maxi-scooters. The global popularity of motor scooters dates from the post-World War II introductions of the Vespa and Lambretta models in Italy. These scooters were intended to provide economical personal transportation (engines from 50 to 150 cc or 3.1 to 9.2 cu in). The original layout is still widely used in this application. Maxi-scooters, with larger engines from 200 to 850 cc (12 to 52 cu in) have been developed for Western markets. Scooters are popular for personal transportation partly due to being more affordable, easier to operate, and more convenient to park and store than a car. Licensing requirements for scooters are easier and cheaper than for cars in most parts of the world, and insurance is usually cheaper. The term motor scooter is sometimes used to avoid confusion with kick scooter, but can then be confused with motorized scooter or e-scooter, a kick-scooter with an electric motor.
Result
Use whitespace-pre-wrap to ensure the whitespace is preserved
formatParagraphs(text: string, options?: { minSentenceCount: number, minCharacterCount: number })

formatInitials

Link Copied!

Generate initials from any string while ignoring common titles

formatInitials('Dr Mick Jagger Snr', { length: 2 })
MJ
Result
formatInitials(text: string, options?: { length?: number })

formatUnixTime

Link Copied!

Format Unix timestamp into a datetime string

formatUnixTime(1724997492)
2024-08-30 05:58:12.000
Result
formatUnixTime(timestamp: number)

formatList

Link Copied!

Create a string of comma-separated values from an array, object, or string with an optional limit and conjunction

formatList('Mick Jagger,Keith Richards,Ronnie Wood,Brian Jones,Ian Stewart,Bill Wyman,Charlie Watts,Mick Taylor', { limit: 3, conjunction: 'and' })
Mick Jagger, Keith Richards, Ronnie Wood and 5 more
Result
formatList(items: string | object | string[], options?: { limit?: number; conjunction?: string })

formatTitle

Link Copied!

Converts a string to title case following the Chicago Manual of Style rules.

formatTitle('Revolutionary scooter trend sweeps the nation. Exploring the surprising surge in "Scooter Mania", but is it more than a fad?')
Revolutionary Scooter Trend Sweeps the Nation. Exploring the Surprising Surge in "Scooter Mania", but is it More than a Fad?
Result
formatTitle(text: string)

formatSentenceCase

Link Copied!

Format a sentence case string

formatSentenceCase('scooters are safe. i like scooters.')
Scooters are safe. I like scooters.
Result
formatSentenceCase(text: string)

formatTextWrap

Link Copied!

Adds a space between the last two words in a string to prevent lonely words.

formatTextWrap('Scooters are the future')
Scooters are the future
Result
Remember `text-wrap: pretty` and `text-wrap: balance` are available for most browsers.
formatTextWrap(text: string)