Module sizes
Some utility functions for formatting of data sizes i.e.
file sizes.
Functions
format (size[, base=1024[, ssuffix=""]]) | Format a size with the given base. |
format10 (size) | Format a size in base 10. |
Functions
- format (size[, base=1024[, ssuffix=""]])
-
Format a size with the given base.
This function returns a string with the last character set accordingly. For example,
sizes.format(2048)
returns"2K"
.base
defaults to 1024. The resulting size is always rounded to the nearest whole number.Parameters:
- size number The size to format
- base
number
What to divide
size
by if it is larger thanbase
(default 1024) - ssuffix
string
A suffix to concatenate if
size >= base
(default "")
Returns:
-
string
The formatted size
- format10 (size)
-
Format a size in base 10.
Equivalent to
sizes.format(size, 1000, "i")
.format10(4096)
returns4Ki
.Parameters:
- size number The size to format
Returns:
-
string
The formatted size