https://github.com/joho/alphakey
Handy little library for converting ints to short strings (for things like url shorteners and the like)
https://github.com/joho/alphakey
Last synced: about 1 year ago
JSON representation
Handy little library for converting ints to short strings (for things like url shorteners and the like)
- Host: GitHub
- URL: https://github.com/joho/alphakey
- Owner: joho
- Created: 2014-01-05T03:50:39.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-12-22T23:39:07.000Z (over 8 years ago)
- Last Synced: 2025-01-26T03:26:19.534Z (over 1 year ago)
- Language: Go
- Size: 4.88 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AlphaKey
For a [Codename](http://codename.io) project I was working on I needed human readable/shareable short keys, so I ended up reimplementing the solution found on [this stack overflow answer about "Bijective Functions"](http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047) in Go and figured it might be of use to anyone else who needs to put together a url shortener or the like.
## Usage
To get going, just import this
```go
import "github.com/joho/alphakey"
```
You can either call a couple of the helper functions directly
```go
key := alphakey.GetKeyForInt(198898042) // returns "ninja"
num := alphakey.GetIntForKey("dgt") // returns 1337
```
Or if you want a bit more control you can instantiate your own converter and control the alphabet used and any offset you might want
```go
converter := &alphakey.Converter{
alphakey.UnambiguousLowercaseAlphabet, // all lower case, no l or o, because humans
497, // an arbitrary offset so early sharers don't get a or b
}
key := converter.GetKey(1988483) // returns "ninja"
num := converter.GetInt("emq") // returns 1337
```
You can also check the [godocs for AlphaKey](http://godoc.org/github.com/joho/alphakey)
## Build Status
[](https://app.wercker.com/project/bykey/c6de7a7f75baca3f7e1848f674c9b8be)
---
© 2013 [John Barton](https://johnbarton.co/), MIT Licenced