-
Notifications
You must be signed in to change notification settings - Fork 0
/
idxn.go
39 lines (30 loc) · 796 Bytes
/
idxn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package idxn
const (
_alphanumeric = "abcdefghijklmnopqrstuvwxyz1234567890"
_alphanumericUpper = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
_alpha = "abcdefghijklmnopqrstuvwxyz"
_alphaUpper = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)
func Alphanumeric(i int) string {
return Custom(i, _alphanumeric)
}
func AlphanumericWithUpper(i int) string {
return Custom(i, _alphanumericUpper)
}
func Alpha(i int) string {
return Custom(i, _alpha)
}
func AlphaWithUpper(i int) string {
return Custom(i, _alphaUpper)
}
func Custom(i int, alpha string) string {
var idx string
l := len(alpha)
mod := i % l
div := i / l
idx += string(alpha[mod])
for j := div - 1; j >= 0; j-- {
idx += Custom(div-j-1, alpha)
}
return idx
}