diff options
author | Jesús Espino <jespinog@gmail.com> | 2018-01-11 16:57:47 +0100 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-01-11 10:57:47 -0500 |
commit | 6990d052d5e95295e729aae28a0d30bfdcb98573 (patch) | |
tree | dc441fdd959997f97cfff298c833a2503cee4a37 /vendor/github.com/icrowley/fake/general.go | |
parent | 0a9200c35d4f3c5c0462135f5f6dfe60bfe364e8 (diff) | |
download | chat-6990d052d5e95295e729aae28a0d30bfdcb98573.tar.gz chat-6990d052d5e95295e729aae28a0d30bfdcb98573.tar.bz2 chat-6990d052d5e95295e729aae28a0d30bfdcb98573.zip |
[XYZ-6] Add sampledata platform command (#8027)
* Add fake dependency
* [XYZ-6] Add sampledata platform command
* Creating EMOJI_NAME_MAX_LENGTH as a constant and using it where needed
Diffstat (limited to 'vendor/github.com/icrowley/fake/general.go')
-rw-r--r-- | vendor/github.com/icrowley/fake/general.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/github.com/icrowley/fake/general.go b/vendor/github.com/icrowley/fake/general.go new file mode 100644 index 000000000..8b1ec7cbd --- /dev/null +++ b/vendor/github.com/icrowley/fake/general.go @@ -0,0 +1,79 @@ +package fake + +var lowerLetters = []rune("abcdefghijklmnopqrstuvwxyz") +var upperLetters = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ") +var numeric = []rune("0123456789") +var specialChars = []rune(`!'@#$%^&*()_+-=[]{};:",./?`) +var hexDigits = []rune("0123456789abcdef") + +func text(atLeast, atMost int, allowLower, allowUpper, allowNumeric, allowSpecial bool) string { + allowedChars := []rune{} + if allowLower { + allowedChars = append(allowedChars, lowerLetters...) + } + if allowUpper { + allowedChars = append(allowedChars, upperLetters...) + } + if allowNumeric { + allowedChars = append(allowedChars, numeric...) + } + if allowSpecial { + allowedChars = append(allowedChars, specialChars...) + } + + result := []rune{} + nTimes := r.Intn(atMost-atLeast+1) + atLeast + for i := 0; i < nTimes; i++ { + result = append(result, allowedChars[r.Intn(len(allowedChars))]) + } + return string(result) +} + +// Password generates password with the length from atLeast to atMOst charachers, +// allow* parameters specify whether corresponding symbols can be used +func Password(atLeast, atMost int, allowUpper, allowNumeric, allowSpecial bool) string { + return text(atLeast, atMost, true, allowUpper, allowNumeric, allowSpecial) +} + +// SimplePassword is a wrapper around Password, +// it generates password with the length from 6 to 12 symbols, with upper characters and numeric symbols allowed +func SimplePassword() string { + return Password(6, 12, true, true, false) +} + +// Color generates color name +func Color() string { + return lookup(lang, "colors", true) +} + +// DigitsN returns n digits as a string +func DigitsN(n int) string { + digits := make([]rune, n) + for i := 0; i < n; i++ { + digits[i] = numeric[r.Intn(len(numeric))] + } + return string(digits) +} + +// Digits returns from 1 to 5 digits as a string +func Digits() string { + return DigitsN(r.Intn(5) + 1) +} + +func hexDigitsStr(n int) string { + var num []rune + for i := 0; i < n; i++ { + num = append(num, hexDigits[r.Intn(len(hexDigits))]) + } + return string(num) +} + +// HexColor generates hex color name +func HexColor() string { + return hexDigitsStr(6) +} + +// HexColorShort generates short hex color name +func HexColorShort() string { + return hexDigitsStr(3) +} |