Documentation ¶
Overview ¶
Package humanize provides functionality for converting numeric strings into more human-friendly representations according to CLDR data and locale rules.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CldrData ¶
type CldrData struct { Long struct { DecimalFormat map[string]string } Short struct { DecimalFormat map[string]string } }
CldrData contains the relevant decimal formats for short and long forms according to the CLDR specification.
type FallbackFunc ¶
FallbackFunc is a user-supplied function invoked when the input string cannot be humanized (for instance, if the input is not an integer).
type Humanizer ¶
type Humanizer struct {
// contains filtered or unexported fields
}
Humanizer is responsible for converting a numeric string into a more human-friendly representation (e.g., "1K") according to its configured Locale, Option, and fallback strategy.
func New ¶
New returns a pointer to a new Humanizer with the given locale, form option (long or short), and fallback function. The fallback function is called whenever the input string cannot be humanized (e.g., non-integer or missing CLDR data).
func (*Humanizer) FormatDecimal ¶ added in v0.5.5
type InvalidNumberError ¶
InvalidNumberError is returned when the provided string cannot be parsed as a valid number by the decimal library.
func (InvalidNumberError) Error ¶
func (e InvalidNumberError) Error() string
Error implements the error interface.
type Locale ¶
type Locale interface { // Data returns locale-specific CLDR formatting data. Data() CldrData // PluralForm determines the appropriate plural category (e.g. "one", // "other") based on the decimal value and a string form of that value. PluralForm(r decimal.Decimal, v string) string // Code returns a BCP-47 locale tag like "en", "ja", etc. Code() language.Tag }
Locale defines the methods needed by Humanizer to format numbers for a particular locale. Implementations must provide both the locale code (e.g., "en", "ja") and CLDR data.