diff options
Diffstat (limited to 'src/cashflow/utils.clj')
| -rw-r--r-- | src/cashflow/utils.clj | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/cashflow/utils.clj b/src/cashflow/utils.clj new file mode 100644 index 0000000..abbd2f9 --- /dev/null +++ b/src/cashflow/utils.clj @@ -0,0 +1,24 @@ +(ns cashflow.utils + (:require [clojure.string :as cstr])) + +(defn- n*string [n string] + (when (string? string) + (->> (for [_ (range n)] string) + (apply str)))) + +(defn string-min-length + "Returns string `s` when length of string is `min-length`, otherwise fills string up with a `filler` character, either before `s` if `position` :before or after `s` if `position` is :after." + [s min-length filler position] + (when (string? s) + (let [filler-string (-> (- min-length (.length s)) + (n*string filler))] + (cond + (= position :before) + (str filler-string s) + + (= position :after) + (str s filler-string) + + :else + s)))) + |
