https://github.com/yogthos/alpha-id
creates a short alphanumeric ID from a numeric ID
https://github.com/yogthos/alpha-id
Last synced: 9 months ago
JSON representation
creates a short alphanumeric ID from a numeric ID
- Host: GitHub
- URL: https://github.com/yogthos/alpha-id
- Owner: yogthos
- License: epl-1.0
- Created: 2015-04-01T19:18:45.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-07-19T16:21:23.000Z (over 1 year ago)
- Last Synced: 2025-04-14T08:53:03.131Z (9 months ago)
- Language: Clojure
- Size: 11.7 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alpha-id
A Clojure library for convering numbers into short alphanumeric IDs.
[](http://clojars.org/alpha-id)
## Usage
The number is coverted to an alphanumeric string and back using the `encode` the `decode` functions respectively. The functions accept the dictionary as their first parameter and the value as the second.
Helper functions are provided for the following dictionary sizes:
* `encode-16`/`decode-16`
* `encode-32`/`decode-32`
* `encode-64`/`decode-64`
* `encode-89`/`decode-89`
Using a larger dictionary results in a shorter ID being generated.
```clojure
(use 'alpha-id.core)
(def dict [\0 \1 \2 \3 \4 \5 \6 \7 \8 \9 \A \B \C \D \E \F])
(encode dict 123456) ;=> "1E240"
(decode dict "1E240") ;=> 123456
(encode-64 9007199254740992) ;=>"fFgnDxSe8"
(decode-64 "fFgnDxSe8") ;=> 9007199254740992
```
## License
Copyright © 2015 Dmitri Sotnikov
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.