Documentation
¶
Overview ¶
Package formatx renders values for human consumption — block numbers, counts, rates, durations, sizes.
It exists so that the same quantity does not get formatted three different ways in three different commands. Anything that turns a number into something a user reads belongs here, and nothing here knows about substreams types.
Every function takes the same Option list rather than coming in named variants, so a caller that wants "N/A" instead of "0s", or decimal units instead of binary ones, asks for that at the call site instead of growing a wrapper next to it.
Index ¶
- func Bytes(bytes uint64, opts ...Option) string
- func Count(n uint64, opts ...Option) string
- func Duration(d time.Duration, opts ...Option) string
- func Integer[T ~uint64](value T, opts ...Option) string
- func JoinNonEmpty(sep string, parts ...string) string
- func Millis(ms float64, opts ...Option) string
- func ModuleLeafName(name string) string
- func Rate(perSecond float64, unit string, opts ...Option) string
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bytes ¶
Bytes renders a byte count in binary units by default — 1.5 MiB — since that is what a file size or a transfer volume is measured in. WithDecimalUnits switches to 1.5 MB.
func Count ¶
Count renders a quantity compactly: 912, 3.4k, 6.8M, 1.2B. Use it where the order of magnitude is the point and the exact figure is not; use BlockNumber when the number identifies something and has to be readable digit by digit.
func Duration ¶
Duration is shorter than time.Duration.String() at the scales that matter to a reader: an age or an estimate never needs sub-second precision, and hours never need seconds.
func Integer ¶
Integer renders a whole number with thousands separators, for block numbers and for exact counts alike — anything a reader has to be able to take in digit by digit, as opposed to Count, which trades those digits for an order of magnitude. The values are uint64 and can in principle exceed what humanize.Comma accepts, hence the big.Int path.
func JoinNonEmpty ¶
JoinNonEmpty assembles "a · b · c" segments, dropping the parts that had no data rather than rendering them as empty separators.
func ModuleLeafName ¶
ModuleLeafName strips the imported-package qualification from a module name: "erc20_metadata:erc20_stores:map_events" becomes "map_events".
Types ¶
type Option ¶
type Option func(*config)
Option adjusts how a value is rendered. Options are shared across every function here; one that does not apply to a given value is simply ignored.
func WithDecimalUnits ¶
func WithDecimalUnits() Option
WithDecimalUnits switches Bytes from binary units to powers of a thousand: 1.5 MB rather than 1.5 MiB.