format

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package format converts typed values into human-readable display strings (times, numbers, byte sizes). It is the output counterpart to internal/parse which converts strings into typed values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(b int64) string

Bytes returns a human-readable byte-size string.

Uses binary units (1024-based): B, KB, MB, GB, etc.

Parameters:

  • b: the byte count to format

Returns:

  • string: human-readable size with unit

func Duration

func Duration(d time.Duration) string

Duration returns a human-readable duration string without a suffix.

Parameters:

  • d: duration to format

Returns:

  • string: human-readable representation (e.g., "3 hours", "1 day", "just now")

func DurationAgo

func DurationAgo(d time.Duration) string

DurationAgo returns a human-readable duration with an "ago" suffix.

Parameters:

  • d: duration to format

Returns:

  • string: relative time (e.g., "3 hours ago", "just now")

func Number

func Number(n int) string

Number returns a number with thousand separators.

Examples: 500 → "500", 1500 → "1,500", 12345 → "12,345"

Parameters:

  • n: the number to format

Returns:

  • string: formatted number with commas

func TimeAgo

func TimeAgo(hours float64, mins int, fallbackDate string) string

TimeAgo returns a human-readable relative time duration.

Examples: "just now", "5 minutes ago", "2 hours ago", "3 days ago", or a formatted date for times older than a week.

Parameters:

  • hours: total hours since the event
  • mins: total minutes since the event
  • fallbackDate: formatted date string for durations older than a week

Returns:

  • string: human-readable relative time

func TruncateFirstLine

func TruncateFirstLine(s string, max int) string

TruncateFirstLine returns the first line of s, capped at max characters.

Parameters:

  • s: Input string (may be multi-line)
  • max: Maximum length including ellipsis

Returns:

  • string: Truncated first line

Types

This section is empty.

Jump to

Keyboard shortcuts

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