sizestr

package
v0.0.0-...-0cf3de4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2016 License: MIT, MIT Imports: 5 Imported by: 0

README

sizestr

Convert 231938 into 232KB

GoDoc Circle CI

Usage
go get github.com/jpillora/sizestr
//use directly
sizestr.ToString(231938) //"232KB"
sizestr.Parse("232KB") //232000
sizestr.Parse("232KiB") //237568
//use with pkg/flag
var b sizestr.Bytes
flag.Var(&b, "size", "the size of my file")
Significant Figures

Default is 3. Set via:

sizestr.ToStringSig(231938, 4) //"231.9KB"
Scale

Default is 1000, standard units dictates that Kilo is 1000, not 1024. Also, see this blog post. Though can set via:

sizestr.ToStringSig(231938, 4, 1024) //"226.5KB"

ToPrecision

This library also contains a Go implementation of JavaScript's Number.prototype.toPrecision

sizestr.ToPrecision(123.456, 4) //123.5
MIT License

Copyright © 2015 Jaime Pillora <dev@jpillora.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LowerCase

func LowerCase()

func MustParse

func MustParse(s string) int64

ParseScale a string into a byte count with a specific scale

func Parse

func Parse(s string) (int64, error)

ParseScale a string into a byte count with a specific scale

func ParseBytesPerKB

func ParseBytesPerKB(s string, bytesPerKB int64) (int64, error)

ParseScale a string into a byte count with a specific scale (defaults to 1000)

func ToPrecision

func ToPrecision(n, p float64) float64

A Go implementation of JavaScript's Math.toPrecision

func ToString

func ToString(n int64) string

Converts a byte count into a byte string

func ToStringSig

func ToStringSig(n int64, sig float64) string

Converts a byte count into a byte string

func ToStringSigBytesPerKB

func ToStringSigBytesPerKB(n int64, sig, bytesPerKB float64) string

Converts a byte count into a byte string

func ToggleCase

func ToggleCase()

ToggleCase changes the case of the scale strings ("MB" -> "mb")

func UpperCase

func UpperCase()

Types

type Bytes

type Bytes int64

*Bytes implements the flags.Value interface

func (*Bytes) Set

func (b *Bytes) Set(s string) error

func (Bytes) String

func (b Bytes) String() string

Jump to

Keyboard shortcuts

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