Skip to content

Commit

Permalink
Unid functionality (#3)
Browse files Browse the repository at this point in the history
Creation of (short) unique id strings
  • Loading branch information
verberktstan authored Jan 27, 2024
1 parent 754d4d5 commit 14ca1d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{:aliases
{:deps
;; Clojure standard library
{org.clojure/clojure {:mvn/version "1.11.0"}}
:aliases
{:repl/reloaded
{:extra-deps {nrepl/nrepl {:mvn/version "1.0.0"}
cider/cider-nrepl {:mvn/version "0.28.7"}
Expand Down
12 changes: 12 additions & 0 deletions src/swark/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
(when input
(some-> input name str/trim non-blank))))

(defn unid
([] (-> (random-uuid) str))
([existing]
(-> existing set? assert)
(reduce
(fn [s char]
(if (and s (-> s existing not) (-> s reverse first #{"-"} not))
(reduced s)
(str s char)))
nil
(seq (unid)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Regarding keywords

Expand Down
5 changes: 5 additions & 0 deletions test/swark/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
nil " "
nil nil))

(t/deftest unid
(t/is (string? (sut/unid)))
(t/is (-> #{"x"} sut/unid count #{1}))
(t/is (-> (reduce (fn [x _] (conj x (sut/unid x))) #{} (range 999)) count #{999})))

(t/deftest ->keyword
(t/are [result match replacement input] (= result (sut/->keyword match replacement input))
:test nil nil :test
Expand Down

0 comments on commit 14ca1d6

Please sign in to comment.