formater

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Decimal
	UnitB  = 1
	UnitKB = 1000
	UnitMB = 1000 * UnitKB
	UnitGB = 1000 * UnitMB
	UnitTB = 1000 * UnitGB
	UnitPB = 1000 * UnitTB
	UnitEB = 1000 * UnitPB

	// Binary
	UnitBiB = 1
	UnitKiB = 1024
	UnitMiB = 1024 * UnitKiB
	UnitGiB = 1024 * UnitMiB
	UnitTiB = 1024 * UnitGiB
	UnitPiB = 1024 * UnitTiB
	UnitEiB = 1024 * UnitPiB
)

http://en.wikipedia.org/wiki/Binary_prefix

Variables

This section is empty.

Functions

func BinaryBytes

func BinaryBytes(size float64, precision ...int) string

BinaryBytes returns a human-readable byte size under binary standard (base 1024) The precision parameter specifies the number of digits after the decimal point, which defaults to 4.

func Comma

func Comma[T constraints.Float | constraints.Integer | string](value T, symbol string) string

Comma add comma to a number value by every 3 numbers from right. ahead by symbol char. if value is invalid number string eg "aa", return empty string Comma("12345", "$") => "$12,345", Comma(12345, "$") => "$12,345"

func DecimalBytes

func DecimalBytes(size float64, precision ...int) string

DecimalBytes returns a human readable byte size under decimal standard (base 1000) The precision parameter specifies the number of digits after the decimal point, which defaults to 4.

func ParseBinaryBytes

func ParseBinaryBytes(size string) (uint64, error)

ParseBinaryBytes return the human readable bytes size string into the amount it represents(base 1024). ParseBinaryBytes("42 mib") -> 44040192, nil

func ParseDecimalBytes

func ParseDecimalBytes(size string) (uint64, error)

ParseDecimalBytes return the human readable bytes size string into the amount it represents(base 1000). ParseDecimalBytes("42 MB") -> 42000000, nil

func Pretty

func Pretty(v any) (string, error)

Pretty data to JSON string.

func PrettyToWriter

func PrettyToWriter(v any, out io.Writer) error

PrettyToWriter pretty encode data to writer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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