Documentation
¶
Overview ¶
Package format implements a small subset of the d3-format mini-DSL plus a strftime-style mini-mapping for time formats. Pure stdlib. See README.md for the supported specifier set.
Number specifier grammar (subset):
[,]?[.<int>]?[Nf|N%|%|d|Ne|Ns]
, thousands separator
.N precision (digits after decimal, or significant figures for s)
f fixed-point ("1234.50")
% percent (multiply by 100, append "%")
d integer
e scientific ("1.234e+03")
s SI prefix ("1k", "1.2M")
Time specifier grammar (subset of strftime):
%Y 4-digit year %m 2-digit month %d 2-digit day-of-month %H 2-digit hour (24h) %M 2-digit minute %S 2-digit second %L 3-digit millisecond %j 3-digit day-of-year
The discriminator between number/time format is the presence of a `%X` directive that is not a bare "%" or "N%" — i.e. anything containing `%Y`, `%m`, etc. is a time format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NumberSpec ¶
type NumberSpec struct {
Thousands bool
Precision int // -1 = unset
HasPrec bool // distinguishes ".0f" from "f"
Type byte // 'f' | '%' | 'd' | 'e' | 's'
}
NumberSpec captures the parsed number format.
type Spec ¶
type Spec struct {
Raw string
Number *NumberSpec
Time *TimeSpec
}
Spec is a parsed format specifier. Either Number or Time is set, never both.
Click to show internal directories.
Click to hide internal directories.