Skip to content

Commit

Permalink
Replace ~ with - in default alphabet
Browse files Browse the repository at this point in the history
* Replace ~ to - in default alphabet

* fix order

Co-Authored-By: Aleksandr Zhuravlev <[email protected]>

* fix order

Co-Authored-By: Aleksandr Zhuravlev <[email protected]>

* Fix tests

Co-Authored-By: Aleksandr Zhuravlev <[email protected]>
  • Loading branch information
JulienMalige and zelark committed Oct 9, 2019
1 parent 6980c17 commit 51fe54d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ nano-id uses [SecureRandom](https://docs.oracle.com/javase/7/docs/api/java/secur
nano-id generates compact IDs with just 21 characters. By using a larger alphabet than UUID, nano-id can generate a greater number of unique IDs, when compared to UUID, with fewer characters (21 versus 36).

### URL-Friendly
nano-id uses URL-friendly characters `[A-Za-z0-9_~]`. Perfect for unique identifiers in web applications.
nano-id uses URL-friendly characters `[A-Za-z0-9_-]`. Perfect for unique identifiers in web applications.

## Usage
### Normal
Expand Down Expand Up @@ -48,7 +48,7 @@ user=> (my-nano-id 10)

Or your custom random number generator, for example
```clojure
(let [alphabet "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"
(let [alphabet "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
time-gen (fn [n] (take n (iterate #(unsigned-bit-shift-right % 6)
(quot (System/currentTimeMillis) 1000))))
time-id (generate alphabet time-gen)]
Expand Down
2 changes: 1 addition & 1 deletion src/nano_id/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


(def alphabet
(vec (map str "_~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")))
(vec (map str "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")))


(defn nano-id
Expand Down
4 changes: 2 additions & 2 deletions test/nano_id/custom_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(is (util/close? distribution 1.0))))))

(testing "custom random"
(let [alphabet "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"
(let [alphabet "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
prng (fn [n] (take n (iterate #(unsigned-bit-shift-right % 6) 2377900801)))
gen-id (generate alphabet prng)]
(is (= (gen-id 6) "2DjzC1")))))
(is (= (gen-id 6) "1CiyB0")))))
2 changes: 1 addition & 1 deletion test/nano_id/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


(defn ^boolean valid-id? [id]
(re-matches #"^[A-Za-z0-9_~]+$" id))
(re-matches #"^[A-Za-z0-9_-]+$" id))


(defn ^boolean close? [^double x ^double y]
Expand Down

0 comments on commit 51fe54d

Please sign in to comment.