barista.run: barista.run/format Index | Files

package format

import "barista.run/format"

Package format provides utility methods for formatting units.

Index

Package Files

bytes.go siunit.go units.go

Constants

const (
    Celsius temperatureUnit = iota
    Fahrenheit
    Kelvin
)

Pass in these constants to SetTemperatureUnit to control the default format.

func Byterate Uses

func Byterate(v unit.Datarate) string

Byterate formats a Datarate in SI units using go-humanize. e.g. Byterate(10 * unit.MegabytePerSecond) == "10 MB/s"

func Bytesize Uses

func Bytesize(v unit.Datasize) string

Bytesize formats a Datasize in SI units using go-humanize. e.g. Bytesize(10 * unit.Megabyte) == "10 MB"

func IByterate Uses

func IByterate(v unit.Datarate) string

IByterate formats a Datarate in IEC units using go-humanize. e.g. Byterate(10 * unit.MebibytePerSecond) == "10 MiB/s"

func IBytesize Uses

func IBytesize(v unit.Datasize) string

IBytesize formats a Datasize in IEC units using go-humanize. e.g. IBytesize(10 * unit.Mebibyte) == "10 MiB"

func SetTemperatureUnit Uses

func SetTemperatureUnit(f temperatureUnit)

SetTemperatureUnit sets the default unit used when formatting temperatures.

type Value Uses

type Value struct {
    Unit string
    // contains filtered or unexported fields
}

Value represents a formatted Unit value.

func SI Uses

func SI(v float64, unit string) Value

SI formats an SI unit value by scaling it to a sensible multiplier, and returns a three-character value (four if negative) and a suffix that's either empty or a single character. e.g. format.SI((20480*unit.Megabyte).Bytes(), "B") == {"20.48000", "GB"} or format.SI((0.001234*unit.Foot).Meter(), "m") == {"376.1232", "µm"}

func SIUnit Uses

func SIUnit(val interface{}) (Value, bool)

SIUnit formats a unit.Unit value to an appropriately scaled base unit. For example, SIUnit(length) is equivalent to SI(length.Meters(), "m"). For non-base units (e.g. feet), use SI(length.Feet(), "ft").

func (Value) Number Uses

func (v Value) Number(width int) string

Number returns a representation that occupies at least `width` characters, increasing precision to fill the available space.

func (Value) String Uses

func (v Value) String() string

String formats the value as a string

func (Value) StringW Uses

func (v Value) StringW(w int) string

StringW formats the value as a string, using the given width for the numeric portion.

type Values Uses

type Values []Value

Values represents an ordered list of values, e.g. hours/minutes/seconds.

func Duration Uses

func Duration(d time.Duration) Values

Duration formats a time.Duration by providing the two most significant units.

func Unit Uses

func Unit(value interface{}) (Values, bool)

Unit formats a unit.Unit value to the most appropriately scaled base unit. For example, Unit(length) is equivalent to SI(length.Meters(), "m"). For non-base units (e.g. feet), use SI(length.Feet(), "ft").

func (Values) String Uses

func (v Values) String() string

String formats the values as a string

Package format imports 7 packages (graph) and is imported by 8 packages. Updated 2019-03-09. Refresh now. Tools for package owners.