discljord-utils.util

clojurise-json-key

(clojurise-json-key k)
Converts JSON string keys (e.g. "fullName") to Clojure keyword keys (e.g. :full-name).

exit

(exit)(exit status-code)(exit status-code message)
Exits the program after printing the given message, and returns the given status code.

getrn

(getrn m k nf)
Like get, but also replaces nil values found in the map with the default value.

human-readable-date-diff

(human-readable-date-diff i1 i2)
Returns a string containing the human readable difference between two instants e.g. "4d 2h 37m 12.379s"

human-readable-size

(human-readable-size size)
Returns a string containing a rounded human readable size of the given number of bytes e.g. 1024 -> "1KB", 1234567890 -> "1.15GB"

in-tz

macro

(in-tz tz & body)
Executes body (assumed to include java-time logic) within the given tzdata timezone (e.g. "Americas/Los_Angeles").

log-exception

(log-exception e)(log-exception e msg)
Logs the given exception and (optional) message at ERROR level.

mapfonk

(mapfonk f m)
Returns a new map where f has been applied to all of the keys of m.

mapfonv

(mapfonv f m)
Returns a new map where f has been applied to all of the values of m.

nth-fibonacci

(nth-fibonacci n)
Returns the nth fibonacci.

parse-int

(parse-int x)
Parses a value (a string or numeric) into a Clojure integer (Java Long or BigInteger), returning nil if parsing failed.  Note: redundant in Clojure v1.11+.

replace-all

(replace-all string replacements)
Takes a sequence of replacements, and applies all of them to the given string, in the order provided.  Each replacement in the sequence is a pair of values to be passed to clojure.string/replace (the 2nd and 3rd arguments).

to-ascii

(to-ascii s)
Converts the given string to ASCII, mapping a small number of Unicode characters (whitespace, hyphens, single & double quotes) to their ASCII equivalents and stripping the rest.

truncate

(truncate s len)
If s is longer than len, truncates it to len-1, trims any whitespace on the right, then adds the Unicode ellipsis (…) character to the end.