Skip to content

Commit

Permalink
v0.1.42 - Unid accepts maps (#21)
Browse files Browse the repository at this point in the history
Make core/unid accept both sets and maps.
  • Loading branch information
verberktstan authored May 29, 2024
2 parents b924671 + a868c89 commit 684224d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Most functionality *should* work in both Clojure and Clojurescript.

Add this dependency to the :deps map in deps.edn:

```org.clojars.stanv/swark {:mvn/version "0.1.41"}```
```org.clojars.stanv/swark {:mvn/version "0.1.42"}```

Require swark.core in your ns form:

Expand Down Expand Up @@ -131,7 +131,7 @@ Or create a repl from your editor, e.g. from emacs; `cider-jack-in-clj`

### Jar creation

Create an uberjar with `clj -X:uberjar :jar swark-0.1.41.jar`
Create an uberjar with `clj -X:uberjar :jar swark-0.1.42.jar`

### Local installation

Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
:exec-fn deps-deploy.deps-deploy/deploy
:exec-args {:installer :remote
:sign-releases? true
:artifact "swark-0.1.41.jar"}}
:artifact "swark-0.1.42.jar"}}
:install
{:extra-deps {slipset/deps-deploy {:mvn/version "0.2.2"}}
:exec-fn deps-deploy.deps-deploy/deploy
:exec-args {:installer :local
:artifact "swark-0.1.41.jar"}}
:artifact "swark-0.1.42.jar"}}

#_#_:build {:extra-paths ["build"]
:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.0" :git/sha "9bd8b8a"}}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<packaging>jar</packaging>
<groupId>org.clojars.stanv</groupId>
<artifactId>swark</artifactId>
<version>0.1.41</version>
<version>0.1.42</version>
<name>swark</name>
<dependencies>
<dependency>
Expand All @@ -26,7 +26,7 @@
<url>https://github.com/verberktstan/swark</url>
<connection>scm:git:git://github.com/verberktstan/swark.git</connection>
<developerConnection>scm:git:ssh://[email protected]/verberktstan/swark.git</developerConnection>
<tag>v0.1.41</tag>
<tag>v0.1.42</tag>
</scm>
<licenses>
<license>
Expand Down
5 changes: 3 additions & 2 deletions src/swark/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@
([existing]
(unid nil existing))
([{:keys [min-length filter-regex no-dashes?] :or {min-length 1}} existing]
(-> existing set? assert)
;; (-> existing set? assert)
(assert (or (map? existing) (set? existing)))
(reduce
(fn [s char]
(if (and s (>= (count s) min-length) (-> s existing not) (-> s reverse first #{"-"} not))
(if (and s (>= (count s) min-length) (->> s (contains? existing) not) (-> s reverse first #{"-"} not))
(reduced s)
(str s char)))
nil
Expand Down
Binary file added swark-0.1.42.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions swark-0.1.41.pom → swark-0.1.42.pom
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<packaging>jar</packaging>
<groupId>org.clojars.stanv</groupId>
<artifactId>swark</artifactId>
<version>0.1.41</version>
<version>0.1.42</version>
<name>swark</name>
<dependencies>
<dependency>
Expand All @@ -26,7 +26,7 @@
<url>https://github.com/verberktstan/swark</url>
<connection>scm:git:git://github.com/verberktstan/swark.git</connection>
<developerConnection>scm:git:ssh://[email protected]/verberktstan/swark.git</developerConnection>
<tag>v0.1.41</tag>
<tag>v0.1.42</tag>
</scm>
<licenses>
<license>
Expand Down
4 changes: 4 additions & 0 deletions test/swark/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@
(t/deftest unid
(t/is (string? (sut/unid)))
(t/is (-> #{"x"} sut/unid count #{1}))
(t/is (-> {"x" :val-of-x} sut/unid count #{1})) ;; Works with maps as well
(t/is (->> #{"xyzab"} (sut/unid {:min-length 5}) count (>= 5)))
(t/is (->> {"xyzab" :val-of-xyzab} (sut/unid {:min-length 5}) count (>= 5)))
(t/is (-> (reduce (fn [x _] (conj x (sut/unid x))) #{} (range 999)) count #{999}))
(t/is (-> (reduce (fn [x _] (assoc x (sut/unid x) :another-val)) {} (range 999)) count #{999}))
(t/is (-> (reduce (fn [x _] (conj x (sut/unid {:min-length 4} x))) #{} (range 999)) count #{999}))
(t/is (-> (reduce (fn [x _] (assoc x (sut/unid {:min-length 4} x) :another-val)) {} (range 999)) count #{999}))
(let [three-digits (sut/unid {:min-length 3 :no-dashes? true :filter-regex #"\d"} #{})
four-letters (sut/unid {:min-length 4 :no-dashes? true :filter-regex #"\D"} #{})
five-chars (sut/unid {:min-length 5} #{})]
Expand Down

0 comments on commit 684224d

Please sign in to comment.