stringutils

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPrecision      = 2
	DefaultBase           = 10
	DefaultFormat         = 'f'
	DefaultNilMapFormat   = "{}"
	DefaultNilSliceFormat = "[]"
	DefaultNilFormat      = "<nil>"
)

Variables

This section is empty.

Functions

func Stringify

func Stringify(value any, opts ...Options) string

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 ad 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 stlib 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).

Types

type Options

type Options struct {
	Base           int
	Format         byte
	Precision      int
	NilFormat      string
	NilMapFormat   string
	NilSliceFormat string
}

Options - stringification options.

Jump to

Keyboard shortcuts

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