format

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package format provides shared formatting helpers for display values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(b float64) string

Bytes formats byte amounts: 540 B, 12.4 KB, 1.2 MB, 3.4 GB.

func Cost

func Cost(dollars float64) string

Cost formats a dollar amount: $142, $9.4k, $1.2M.

func Count

func Count(n int64) string

Count renders an integer, showing "—" for zero.

func FirstSentence added in v1.18.0

func FirstSentence(text string) string

FirstSentence returns the first sentence of text (up to ". " or "; "), or the first 120 characters with a word-boundary cutoff if no sentence break is found.

func Percent added in v1.18.0

func Percent(fraction float64) string

Percent formats a fraction as a percentage: 0.68 → "68%", 0.004 → "<1%".

func TitleCase

func TitleCase(slug string) string

TitleCase converts a snake_case slug to Title Case. "bot_traffic" → "Bot Traffic", "pii_leakage" → "Pii Leakage".

func Volume

func Volume(eventsPerHour float64) string

Volume formats events/hr: 892, 45.3k, 2.1M.

func YearlyCost

func YearlyCost(costPerHour float64) string

YearlyCost formats an hourly USD rate as yearly: $0/yr, $1.7k/yr, $110k/yr.

func YearlyCostPtr added in v1.18.0

func YearlyCostPtr(costPerHour *float64) string

YearlyCostPtr formats a nullable hourly rate: nil → "—", 0 → "$0/yr", positive → "~$1.7k/yr". Use this at display boundaries where the value may not yet be estimated (nil) vs estimated at zero.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL