No description
- V 98.4%
- AMPL 1.6%
| .github | ||
| .editorconfig | ||
| human_bytes.v | ||
| human_bytes_test.v | ||
| license.md | ||
| readme.md | ||
| v.mod | ||
human_bytes
Converts bytes into human-friendly strings.
Note that it uses base-10 (e.g. kilobyte). Read about the difference between kilobyte and kibibyte.
Install
$ v install mikerockett.humanbytes
Use
import human_bytes { convert, convert_opt }
// Normal conversions
convert(10) // 10 B
convert(1001) // 1 kB
// Conversions with options
convert_opt(1001, signed: true) // +1 kB
convert_opt(1001, bits: true) // 1 kbit
convert_opt(1e16, binary: true) // 8.88 PiB
convert_opt(1025, bits: true, binary: true, signed: true) // +1 kibit
API
convert(input_val)
input_val f64
The number to format.
convert_opt(input_val, options)
options struct Options
signed bool = false
Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
bits bool = false
Format the number as bits instead of bytes. This can be useful when, for example, referring to bit rate.
binary bool = false
Format the number using the Binary Prefix instead of the SI Prefix. This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.
Thanks
This work is based on pretty-bytes for JavaScript by Sindre.