Liking cljdoc? Tell your friends :D

clj-commons.humanize


datetimeclj/s

(datetime then-dt
          &
          {:keys [now-dt suffix prefix]
           :or {now-dt (jt.ldt/now) suffix "ago" prefix "in"}})

Given a java.time.LocalDate or java.time.LocalDateTime, returns a human-friendly representation of the amount of time elapsed compared to now.

Optional keyword args:

  • :now-dt - specify the value for 'now'
  • :prefix - adjust the verbiage for times in the future
  • :suffix - adjust the verbiage for times in the past
Given a java.time.LocalDate or java.time.LocalDateTime, returns a
human-friendly representation of the amount of time elapsed compared to now.

 Optional keyword args:
* :now-dt - specify the value for 'now'
* :prefix - adjust the verbiage for times in the future
* :suffix - adjust the verbiage for times in the past
sourceraw docstring

durationclj/s

(duration duration-ms)
(duration duration-ms options)

Converts duration, in milliseconds, into a string describing it in terms of years, months, weeks, days, hours, minutes, and seconds.

Ex:

(duration 325100) => "five minutes, twenty-five seconds"

The months and years periods are not based on actual calendar, so are approximate; this function works best for shorter periods of time.

The optional options map allow some control over the result.

:list-format (default: a function) can be set to a function such as oxford

:number-format (default: numberword) function used to format period counts

:short-text (default: "less than a second")

Converts duration, in milliseconds, into a string describing it in terms
of years, months, weeks, days, hours, minutes, and seconds.

Ex:

   (duration 325100) => "five minutes, twenty-five seconds"

The months and years periods are not based on actual calendar, so are approximate; this
function works best for shorter periods of time.

The optional options map allow some control over the result.

:list-format (default: a function) can be set to a function such as oxford

:number-format (default: numberword) function used to format period counts

:short-text (default: "less than a second") 
sourceraw docstring

filesizeclj/s

(filesize bytes & {:keys [binary format] :or {binary false format "%.1f"}})

Format a number of bytes as a human readable filesize (eg. 10 kB). By default, decimal suffixes (kB, MB) are used. Passing :binary true will use binary suffixes (KiB, MiB) instead.

Format a number of bytes as a human readable filesize (eg. 10 kB). By
default, decimal suffixes (kB, MB) are used.  Passing :binary true will use
binary suffixes (KiB, MiB) instead.
sourceraw docstring

format-delta-strclj/s

(format-delta-str amount time-unit suffix prefix future-time?)
source

intcommaclj/s

(intcomma num)

Converts an integer to a string containing commas. every three digits. For example, 3000 becomes '3,000' and 45000 becomes '45,000'.

Converts an integer to a string containing commas. every three digits.
For example, 3000 becomes '3,000' and 45000 becomes '45,000'. 
sourceraw docstring

intwordclj/s

(intword num & {:keys [format] :or {format "%.1f"}})

Converts a large integer to a friendly text representation. Works best for numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'. Supports up to decillion (33 digits) and googol (100 digits).

Converts a large integer to a friendly text representation. Works best for
numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000
becomes '1.2 million' and '1200000000' becomes '1.2 billion'.  Supports up to
decillion (33 digits) and googol (100 digits).
sourceraw docstring

numberwordclj/s

(numberword num)

Takes a number and return a full written string form. For example, 23237897 will be written as "twenty-three million two hundred and thirty-seven thousand eight hundred and ninety-seven".

Takes a number and return a full written string form. For example,
23237897 will be written as "twenty-three million two hundred and
thirty-seven thousand eight hundred and ninety-seven".  
sourceraw docstring

ordinalclj/s

(ordinal num)

Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd', 3 is '3rd', etc.

Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
3 is '3rd', etc.
sourceraw docstring

oxfordclj/s

(oxford coll
        &
        {:keys [maximum-display truncate-noun number-format]
         :or {maximum-display 4 number-format str}})

Converts a list of items to a human-readable string, such as "apple, pear, and 2 other fruits".

Options: :maximum-display - the maximum number of items to display before identifying the remaining count (default: 4) :truncate-noun - the string used to identify the type of items in the list, e.g., "fruit" - will be pluralized if necessary :number-format - function used to format the number of additional items in the list (default: str)

Converts a list of items to a human-readable string, such as "apple, pear, and 2 other fruits".

Options:
:maximum-display - the maximum number of items to display before identifying the remaining count (default: 4)
:truncate-noun - the string used to identify the type of items in the list, e.g., "fruit" - will
be pluralized if necessary
:number-format - function used to format the number of additional items in the list (default: `str`)
sourceraw docstring

relative-datetimeclj/s

(relative-datetime then-dt
                   &
                   {:keys [now-dt suffix prefix number-format max-terms
                           short-text list-format brief?]
                    :or {now-dt (jt.ldt/now)
                         max-terms 2
                         number-format numberword
                         list-format default-list-format
                         short-text "a moment"
                         suffix "ago"
                         prefix "in"}})

Given a LocalDate or LocalDateTime, returns a human friendly expression of the span of time between now and that time (in the future or past). This acts like a mix of datetime and duration.

Options:

:brief? - if true, then only the first character of each period is used, and the number format is forced to str; e.g. "2h, 15m ago" :now-dt - overrides check for current time (used mostly for testing) :max-terms - maximum consecutive terms to use :number-format - used to convert period counts to a string; overridden to str if brief? :list-format - function used to combine strings; default is to separate by commas :short-text - text to use when gap is less than a second, defaults to "a moment" :prefix - prefix text used when then is in the future, defaults to "in" :suffix - suffix text used when then is in the past, defaults to "ago"

Given a LocalDate or LocalDateTime, returns a human friendly expression
of the span of time between now and that time (in the future or past).
This acts like a mix of `datetime` and `duration`.

Options:

:brief? - if true, then only the first character of each period is used, and the number format is forced
to `str`; e.g. "2h, 15m ago"
:now-dt - overrides check for current time (used mostly for testing)
:max-terms - maximum consecutive terms to use
:number-format - used to convert period counts to a string; overridden to `str` if `brief?`
:list-format - function used to combine strings; default is to separate by commas
:short-text - text to use when gap is less than a second, defaults to "a moment"
:prefix - prefix text used when then is in the future, defaults to "in"
:suffix - suffix text used when then is in the past, defaults to "ago"
sourceraw docstring

space-list-formatclj/s

(space-list-format strings)

Joins the strings together with a space.

Joins the strings together with a space.
sourceraw docstring

truncateclj/s

(truncate string length)
(truncate string length suffix)

Truncate a string with suffix (ellipsis by default) if it is longer than specified length.

Truncate a string with suffix (ellipsis by default) if it is
longer than specified length.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close