Import std.text.humanize
std.text.humanize
std.text.humanize: values as people say them, in English. Plurals ("3 enemies"), how long ago or from now a time is ("3 minutes ago"), ordinals ("22nd"), numbers in words ("forty-two"), and a name in each case style a program uses: snake_case, camelCase, PascalCase, and kebab-case. FormatBytes and FormatDuration say a size ("1.2 MB") and a Duration ("1 hour and 30 minutes").
std/text/humanize.fb
Types
Humanize
class
Public Class Humanize
Humanize's operations.
-
word's plural: "enemy" is "enemies", "box" "boxes", "leaf" "leaves", "child" "children", and "sheep" "sheep". Of several words, the last one's. A word keeps its capitals, as "GameObject" does in "GameObjects", and one in capitals has its ending in them too. -
countandword, thewordin its plural unlesscountis 1 or -1: "3 enemies", "1 enemy", and "0 enemies". -
How long ago a time
secondsfrom now was, whensecondsis negative, "3 minutes ago", or how soon it will be, "in 3 minutes", rounded to the unit people would say: "just now" under 45 seconds either way, then a minute, minutes, an hour, hours, a day, days, a month, months, a year, and years. -
How long ago a time
dbefore now was, whendis before 0, or how soon one d from now will be, as Relative says it ofd's whole seconds: "3 minutes ago" and "in 2 hours". -
nwith its ordinal's ending: "1st", "2nd", "3rd", "4th", "11th", "22nd", and "113th". -
nin words: "zero", "forty-two", "one thousand two hundred thirty-four", and "minus seven". -
text's words in snake_case: "Hello World", "helloWorld", and "HTTPServer2" are "hello_world", "hello_world", and "http_server2". Words are split at spaces, punctuation, and capitals that start one, and a run of capitals is one word. -
text's words in kebab-case: "hello-world". -
text's words in camelCase: "helloWorld", "httpServer2". -
text's words in PascalCase: "HelloWorld", "HttpServer2".
Functions
FormatBytes
function
Public Function FormatBytes(count: Int64, binary: Bool = False): String
count bytes as people say them, in the largest unit they make at least 1 of, to a tenth,
rounded half up: "1.2 MB", "999 B", and "-3.4 GB". The units are 1000 apart, or with binary,
1024: "1.2 MiB".
FormatDuration
function
Public Function FormatDuration(d: Duration): String
d in words: each of its days, hours, minutes, and seconds that isn't 0, the seconds with their
fraction, as "1 hour, 2 minutes, and 3.5 seconds" and "2 days and 1 minute". Under a second,
it's in its largest unit: "250 milliseconds", "1.5 microseconds", and "80 nanoseconds". It's
"0 seconds", and one before 0 is "minus" one after.
Report an issue with this page or with FutureBlitz on GitHub.