Skip to content

Commit 51fe54d

Browse files
JulienMaligezelark
andcommitted
Replace ~ with - in default alphabet
* Replace ~ to - in default alphabet * fix order Co-Authored-By: Aleksandr Zhuravlev <kvark.lark@gmail.com> * fix order Co-Authored-By: Aleksandr Zhuravlev <kvark.lark@gmail.com> * Fix tests Co-Authored-By: Aleksandr Zhuravlev <kvark.lark@gmail.com>
1 parent 6980c17 commit 51fe54d

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nano-id uses [SecureRandom](https://docs.oracle.com/javase/7/docs/api/java/secur
1212
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).
1313

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

1717
## Usage
1818
### Normal
@@ -48,7 +48,7 @@ user=> (my-nano-id 10)
4848

4949
Or your custom random number generator, for example
5050
```clojure
51-
(let [alphabet "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"
51+
(let [alphabet "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
5252
time-gen (fn [n] (take n (iterate #(unsigned-bit-shift-right % 6)
5353
(quot (System/currentTimeMillis) 1000))))
5454
time-id (generate alphabet time-gen)]

src/nano_id/core.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
(def alphabet
6-
(vec (map str "_~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")))
6+
(vec (map str "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")))
77

88

99
(defn nano-id

test/nano_id/custom_test.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
(is (util/close? distribution 1.0))))))
2323

2424
(testing "custom random"
25-
(let [alphabet "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"
25+
(let [alphabet "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
2626
prng (fn [n] (take n (iterate #(unsigned-bit-shift-right % 6) 2377900801)))
2727
gen-id (generate alphabet prng)]
28-
(is (= (gen-id 6) "2DjzC1")))))
28+
(is (= (gen-id 6) "1CiyB0")))))

test/nano_id/util.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

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

77

88
(defn ^boolean close? [^double x ^double y]

0 commit comments

Comments
 (0)