sizefmt 0.2.0
A small library to format file sizes.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
sizefmt
A small library to format file sizes.
Synopsis
unittest
{
assert("%s".format(Size(1)) == "1 B");
assert("%s".format(Size(42)) == "42 B");
assert("%g".format(Size(1024)) == "1 KB");
assert("%.2f".format(Size(2_590_000)) == "2.47 MB");
}
You can control the formatting by creating a new type with different options:
unittest
{
alias MySize = SizeBase!(config!`{
symbol: "O",
unitName: "octet",
unitNamePlural: "octets",
prefixUse: PrefixUse.IEC,
spacing: Spacing.tabular,
useNameIfNoPrefix: true
}`);
assert("|%4.1f|".format(MySize(1)) == "| 1 octet |");
assert("|%4.1f|".format(MySize(42)) == "| 42 octets|");
assert("|%4.1f|".format(MySize(1024)) == "| 1.0 KiO |");
assert("|%4.1f|".format(MySize(2_590_000)) == "| 2.5 MiO |");
}
License: BSL 1.0
Copyright 2014, Nicolas Sicard
- Registered by Nicolas Sicard
- 0.2.0 released 10 years ago
- biozic/sizefmt
- github.com/biozic/sizefmt
- BSL-1.0
- Copyright © 2014, Nicolas Sicard
- Authors:
- Dependencies:
- none
- Versions:
-
0.3.1 2015-Oct-29 0.3.0 2015-Apr-05 0.2.0 2014-Oct-31 0.1.0 2014-Oct-26 ~master 2018-Jan-04 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
536 downloads total
-
- Score:
- 1.3
- Short URL:
- sizefmt.dub.pm