1package util
2
3import (
4	"regexp"
5
6	"github.com/teris-io/shortid"
7)
8
9var allowedChars = shortid.DefaultABC
10
11var validUIDPattern = regexp.MustCompile(`^[a-zA-Z0-9\-\_]*$`).MatchString
12
13func init() {
14	gen, _ := shortid.New(1, allowedChars, 1)
15	shortid.SetDefault(gen)
16}
17
18// IsValidShortUID checks if short unique identifier contains valid characters
19func IsValidShortUID(uid string) bool {
20	return validUIDPattern(uid)
21}
22
23// IsShortUIDTooLong checks if short unique identifier is too long
24func IsShortUIDTooLong(uid string) bool {
25	return len(uid) > 40
26}
27
28// GenerateShortUID generates a short unique identifier.
29func GenerateShortUID() string {
30	return shortid.MustGenerate()
31}
32