Skip to content
FutureBlitz

    Install

    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.

    std/text/humanize.fb, line 17

    • Public Static Method Plural(word: String): String static method #

      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.

    • Public Static Method Plural(count: Int64, word: String): String static method #

      count and word, the word in its plural unless count is 1 or -1: "3 enemies", "1 enemy", and "0 enemies".

    • Public Static Method Relative(seconds: Int64): String static method #

      How long ago a time seconds from now was, when seconds is 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.

    • Public Static Method Relative(d: Duration): String static method #

      How long ago a time d before now was, when d is before 0, or how soon one d from now will be, as Relative says it of d's whole seconds: "3 minutes ago" and "in 2 hours".

    • Public Static Method Ordinal(n: Int64): String static method #

      n with its ordinal's ending: "1st", "2nd", "3rd", "4th", "11th", "22nd", and "113th".

    • Public Static Method Words(n: Int64): String static method #

      n in words: "zero", "forty-two", "one thousand two hundred thirty-four", and "minus seven".

    • Public Static Method SnakeCase(text: String): String static method #

      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.

    • Public Static Method KebabCase(text: String): String static method #

      text's words in kebab-case: "hello-world".

    • Public Static Method CamelCase(text: String): String static method #

      text's words in camelCase: "helloWorld", "httpServer2".

    • Public Static Method PascalCase(text: String): String static method #

      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".

    std/text/humanize.fb, line 257

    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.

    std/text/humanize.fb, line 281

    Report an issue with this page or with FutureBlitz on GitHub.