-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelpers.go
More file actions
203 lines (173 loc) · 4.07 KB
/
helpers.go
File metadata and controls
203 lines (173 loc) · 4.07 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package gofaker
import (
"github.com/tinygg/gofaker/data"
"math"
"math/rand"
"strings"
)
const lowerStr = "abcdefghijklmnopqrstuvwxyz"
const upperStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const numericStr = "0123456789"
const specialStr = "!@#$%&*+-_=?:;,.|(){}<>"
const spaceStr = " "
const allStr = lowerStr + upperStr + numericStr + specialStr + spaceStr
const hashtag = '#'
const questionmark = '?'
// Check if in lib
func dataCheck(dataVal []string) bool {
var checkOk bool
if len(dataVal) == 2 {
_, checkOk = data.Data()[dataVal[0]]
if checkOk {
_, checkOk = data.Data()[dataVal[0]][dataVal[1]]
}
}
return checkOk
}
// Check if in lib
func intDataCheck(dataVal []string) bool {
if len(dataVal) != 2 {
return false
}
_, checkOk := data.IntData[dataVal[0]]
if checkOk {
_, checkOk = data.IntData[dataVal[0]][dataVal[1]]
}
return checkOk
}
// Get Random Value
func getRandValue(dataVal []string) string {
if !dataCheck(dataVal) {
return ""
}
return data.Data()[dataVal[0]][dataVal[1]][rand.Intn(len(data.Data()[dataVal[0]][dataVal[1]]))]
}
// Get Random Integer Value
func getRandIntValue(dataVal []string) int {
if !intDataCheck(dataVal) {
return 0
}
return data.IntData[dataVal[0]][dataVal[1]][rand.Intn(len(data.IntData[dataVal[0]][dataVal[1]]))]
}
// Replace # with numbers
func replaceWithNumbers(str string) string {
if str == "" {
return str
}
bytestr := []byte(str)
for i := 0; i < len(bytestr); i++ {
if bytestr[i] == hashtag {
bytestr[i] = byte(randDigit())
}
}
if bytestr[0] == '0' {
bytestr[0] = byte(rand.Intn(8)+1) + '0'
}
return string(bytestr)
}
// Replace ? with ASCII lowercase letters
func replaceWithLetters(str string) string {
if str == "" {
return str
}
bytestr := []byte(str)
for i := 0; i < len(bytestr); i++ {
if bytestr[i] == questionmark {
bytestr[i] = byte(randLetter())
}
}
return string(bytestr)
}
// Replace ? with ASCII lowercase letters between a and f
func replaceWithHexLetters(str string) string {
if str == "" {
return str
}
bytestr := []byte(str)
for i := 0; i < len(bytestr); i++ {
if bytestr[i] == questionmark {
bytestr[i] = byte(randHexLetter())
}
}
return string(bytestr)
}
// Generate random lowercase ASCII letter
func randLetter() rune {
allLetters := upperStr + lowerStr
return rune(allLetters[rand.Intn(len(allLetters))])
}
func randCharacter(s string) string {
return string(s[rand.Int63()%int64(len(s))])
}
// Generate random lowercase ASCII letter between a and f
func randHexLetter() rune {
return rune(byte(rand.Intn(6)) + 'a')
}
// Generate random ASCII digit
func randDigit() rune {
return rune(byte(rand.Intn(10)) + '0')
}
// Generate random integer between min and max
func randIntRange(min, max int) int {
if min == max {
return min
}
return rand.Intn((max+1)-min) + min
}
func randFloat32Range(min, max float32) float32 {
if min == max {
return min
}
return rand.Float32()*(max-min) + min
}
func randFloat64Range(min, max float64) float64 {
if min == max {
return min
}
return rand.Float64()*(max-min) + min
}
func toFixed(num float64, precision int) float64 {
output := math.Pow(10, float64(precision))
return float64(math.Floor(num*output)) / output
}
func equalSliceString(a, b []string) bool {
sizeA, sizeB := len(a), len(b)
if sizeA != sizeB {
return false
}
for i, va := range a {
vb := b[i]
if va != vb {
return false
}
}
return true
}
func funcLookupSplit(str string) []string {
out := []string{}
for str != "" {
if strings.HasPrefix(str, "[") {
startIndex := strings.Index(str, "[")
endIndex := strings.Index(str, "]")
val := str[(startIndex) : endIndex+1]
out = append(out, strings.TrimSpace(val))
str = strings.Replace(str, val, "", 1)
// Trim off comma if it has it
if strings.HasPrefix(str, ",") {
str = strings.Replace(str, ",", "", 1)
}
} else {
strSplit := strings.SplitN(str, ",", 2)
strSplitLen := len(strSplit)
if strSplitLen >= 1 {
out = append(out, strings.TrimSpace(strSplit[0]))
}
if strSplitLen >= 2 {
str = strSplit[1]
} else {
str = ""
}
}
}
return out
}