-
Notifications
You must be signed in to change notification settings - Fork 0
/
namingo.go
70 lines (59 loc) · 1.25 KB
/
namingo.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package namingo
import (
"math/rand"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
const (
title = "title"
upper = "upper"
lower = "lower"
)
func Adjective() string {
return adjectives[rand.Intn(len(adjectives))]
}
func Name() string {
return nouns[rand.Intn(len(nouns))]
}
func DefaultCase() string {
return lower
}
func UpperCase() string {
return upper
}
func LowerCase() string {
return lower
}
func TitleCase() string {
return title
}
// Generate generates a random name
// Takes a number of words and a separator
// If a single word is requested, it will return a name
// If more than one word is requested, it will return an adjective + name
func Generate(words int, sep string, tf string) string {
var rs string
if words == 1 {
rs = Name()
return rs
}
rs = Adjective() + sep + Name()
switch tf {
case "": // if no case is specified, use lowercase as default
c := cases.Lower(language.English)
rs = c.String(rs)
case upper:
c := cases.Upper(language.English)
rs = c.String(rs)
case lower:
c := cases.Lower(language.English)
rs = c.String(rs)
case title:
c := cases.Title(language.English)
rs = c.String(rs)
default: // defaults to lowercase
c := cases.Lower(language.English)
rs = c.String(rs)
}
return rs
}