forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/brianvoe/gofakeit/v6/word_general.go

56 lines
957 B
Go
Raw Normal View History

2024-04-26 19:30:35 +00:00
package gofakeit
import (
"math/rand"
"strings"
"github.com/brianvoe/gofakeit/v6/data"
)
// Word will generate a random word
2024-04-26 19:30:35 +00:00
func Word() string { return word(globalFaker.Rand) }
// Word will generate a random word
2024-04-26 19:30:35 +00:00
func (f *Faker) Word() string { return word(f.Rand) }
func word(r *rand.Rand) string {
2024-04-26 19:30:35 +00:00
word := getRandValue(r, []string{"word", randomString(r, data.WordKeys)})
// Word may return a couple of words, if so we will split on space and return a random word
2024-04-26 19:30:35 +00:00
if strings.Contains(word, " ") {
2024-04-26 19:30:35 +00:00
return randomString(r, strings.Split(word, " "))
2024-04-26 19:30:35 +00:00
}
return word
2024-04-26 19:30:35 +00:00
}
func addWordGeneralLookup() {
2024-04-26 19:30:35 +00:00
AddFuncLookup("word", Info{
Display: "Word",
Category: "word",
2024-04-26 19:30:35 +00:00
Description: "Basic unit of language representing a concept or thing, consisting of letters and having meaning",
Example: "man",
Output: "string",
2024-04-26 19:30:35 +00:00
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
2024-04-26 19:30:35 +00:00
return word(r), nil
2024-04-26 19:30:35 +00:00
},
})
2024-04-26 19:30:35 +00:00
}