Utility functions used internally in Tornado.
Utility functions used internally in Tornado.
Moved from this ns to util in version 0.2.10 to prevent cyclic dependency needed in ns-kw->str
.
Moved from this ns to util in version 0.2.10 to prevent cyclic dependency needed in `ns-kw->str`.
(->fixed x)
(->fixed x d)
Rounds a given number x to d decimal digits, or 0 by default.
Rounds a given number x to d decimal digits, or 0 by default.
(apply-avg coll)
Same as (apply average coll)
Same as (apply average coll)
(average & args)
Computes the average of 1 or more numbers. Accepts elements directly, use apply-avg for a sequence.
Computes the average of 1 or more numbers. Accepts elements directly, use apply-avg for a sequence.
(between value n1 n2)
Returns true if value is smaller than or equal n1 and greater than or equal n2.
Returns true if value is smaller than or equal n1 and greater than or equal n2.
(conjv v value)
Equal to (conj (vec v) value).
Equal to (conj (vec v) value).
A precalculated map for very fast conversions of hexadecimal strings in format "xx" to base10 numbers.
A precalculated map for very fast conversions of hexadecimal strings in format "xx" to base10 numbers.
(double-hex? str-expr)
Returns true if every 2-characters substring of the given string expression matches to the hexadecimal characters.
Returns true if every 2-characters substring of the given string expression matches to the hexadecimal characters.
(get-str-form x)
If the argument is a symbol, a keyword or a string, returns its string form. Otherwise, returns nil.
If the argument is a symbol, a keyword or a string, returns its string form. Otherwise, returns nil.
(in-range val min-val max-val)
If the value is not in range of min-val and max-val, returns the value of the corresponding border which is nearer to the value, otherwise returns the value.
If the value is not in range of min-val and max-val, returns the value of the corresponding border which is nearer to the value, otherwise returns the value.
(int* x)
Converts a float to an integer if the value would remain equal. Ratios will be converted to a float, or, again, to an integer if possible.
Converts a float to an integer if the value would remain equal. Ratios will be converted to a float, or, again, to an integer if possible.
(named? x)
Returns true if the argument is a symbol, a keyword or a string.
Returns true if the argument is a symbol, a keyword or a string.
(percent->number value)
(percent->number value throw-if-no-match)
If the argument is a value in percent, convert it to a corresponding numeral value. Throws an exception if the optional 2nd argument has a truthy value and the input type is none of string, number or CSSUnit instance. Otherwise thís function does not do anything and will return the input.
(percent->int 0.5) => 0.5
(percent->int "75%") ; can be "75 %" as well => 0.75
(percent->int (tornado.units/percent 35)) => 0.35
If the argument is a value in percent, convert it to a corresponding numeral value. Throws an exception if the optional 2nd argument has a truthy value and the input type is none of string, number or CSSUnit instance. Otherwise thís function does not do anything and will return the input. (percent->int 0.5) => 0.5 (percent->int "75%") ; can be "75 %" as well => 0.75 (percent->int (tornado.units/percent 35)) => 0.35
(percent-with-symbol-append value)
Multiplies a number with 100 to get a percentage value of it. Returns a string form of it with "%" appended. Non-numbers are returned unaffected.
Multiplies a number with 100 to get a percentage value of it. Returns a string form of it with "%" appended. Non-numbers are returned unaffected.
(prune-nils m)
Given a map, removes all keys having nil value. If the pruned map is empty, returns nil.
Given a map, removes all keys having nil value. If the pruned map is empty, returns nil.
(round-4d x)
Rounds a given number to 4 decimal digits, which should be enough in most cases. Used for inaccurate calculations, e.g.: (* 1.0 100)
Rounds a given number to 4 decimal digits, which should be enough in most cases. Used for inaccurate calculations, e.g.: (* 1.0 100)
(some-instance? expr & classes)
Returns true if the expression is an instance of any from the given classes.
Returns true if the expression is an instance of any from the given classes.
(str-butlast s)
Returns the given string without the last character.
Returns the given string without the last character.
(to-percent-float value)
Parses a percentage from a string or multiplies a number with 100 to get a percentage value of it: (tpf "12%") => 12 (tpf "3") => 300 (tpf 8) => 800
Parses a percentage from a string or multiplies a number with 100 to get a percentage value of it: (tpf "12%") => 12 (tpf "3") => 300 (tpf 8) => 800
(toLower c)
Characters [A-F] will be transformed to [a-f], other chars will be returned unchanged.
Characters [A-F] will be transformed to [a-f], other chars will be returned unchanged.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close