Documentation
¶
Index ¶
- Constants
- func Capitalize(str string) string
- func Contains(str, substr string, caseInsensitive bool) bool
- func DefaultIfEmpty(str, def string) string
- func EllipsisMiddle(str string, maxLength int) string
- func JoinNonEmpty(strs []string, sep string) string
- func PadLeft(str string, padWith string, padTo int) string
- func PadRight(str string, padWith string, padTo int) string
- func RemoveWhitespace(str string) string
- func Reverse(str string) string
- func SplitAndTrim(str, sep string) []string
- func Stringify(value any, opts ...Options) string
- func ToCamelCase(str string) string
- func ToKebabCase(str string) string
- func ToSnakeCase(str string) string
- func Truncate(str string, maxLength int, suffix string) string
- type Options
Constants ¶
const ( DefaultPrecision = 2 DefaultBase = 10 DefaultFormat = 'f' DefaultNilMapFormat = "{}" DefaultNilSliceFormat = "[]" DefaultNilFormat = "<nil>" )
Default options.
Variables ¶
This section is empty.
Functions ¶
func Capitalize ¶ added in v1.8.0
Capitalize capitalizes the first letter of the given string. Returns the string unchanged if empty.
func Contains ¶ added in v1.9.0
Contains checks if string contains substring with optional case-insensitive matching.
func DefaultIfEmpty ¶ added in v1.9.0
DefaultIfEmpty returns default if string is empty or only whitespace. Returns the trimmed string if not empty.
func EllipsisMiddle ¶ added in v1.9.0
EllipsisMiddle truncates middle of string with ellipsis if longer than maxLength. Keeps approximately equal parts from start and end.
func JoinNonEmpty ¶ added in v1.9.0
JoinNonEmpty joins strings with a separator, skipping empty strings.
func PadLeft ¶ added in v1.3.1
PadLeft - Pad a string to a certain length (in bytes) with another string on the left side.
func PadRight ¶ added in v1.3.1
PadRight - Pad a string to a certain length (in bytes) with another string on the right side.
func RemoveWhitespace ¶ added in v1.9.0
RemoveWhitespace removes all whitespace from string.
func SplitAndTrim ¶ added in v1.9.0
SplitAndTrim splits a string by separator and trims whitespace from each part. Empty parts are removed from the result.
func Stringify ¶
Stringify receives an arbitrary value and converts it into a string. Stringify also accepts an options object with the following properties:
Options.NilFormat: the string format for nil values, defaults to "<nil>".
Options.NilMapFormat: the string format for nil map objects, defaults to "{}".
Options.NilSliceFormat: the string format for nil slice objects, defaults to "[]".
Options.Base: a number between 2-36 as the base when converting ints and uints to strings, defaults to Base 10.
Options.Precision: number of digits to include when converting floats and complex numbers to strings, defaults to 2.
Options.Format: the number notation format, using the stdlib ftoa functionalities, defaults to 'f':
'b' (-ddddp±ddd, a binary exponent),
'e' (-d.dddde±dd, a decimal exponent),
'E' (-d.ddddE±dd, a decimal exponent),
'f' (-ddd.dddd, no exponent),
'g' ('e' for large exponents, 'f' otherwise),
'G' ('E' for large exponents, 'f' otherwise),
'x' (-0xd.ddddp±ddd, a hexadecimal fraction and binary exponent), or
'X' (-0Xd.ddddP±ddd, a hexadecimal fraction and binary exponent).
func ToCamelCase ¶ added in v1.9.0
ToCamelCase converts string to camelCase. Splits on spaces, hyphens, and underscores.
func ToKebabCase ¶ added in v1.9.0
ToKebabCase converts string to kebab-case.
func ToSnakeCase ¶ added in v1.9.0
ToSnakeCase converts string to snake_case.