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-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
func Word() string { return word(globalFaker.Rand) }
|
|
|
|
|
|
|
|
// Word will generate a random word
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
func (f *Faker) Word() string { return word(f.Rand) }
|
|
|
|
|
|
|
|
func word(r *rand.Rand) string {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
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-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
if strings.Contains(word, " ") {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
return randomString(r, strings.Split(word, " "))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return word
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func addWordGeneralLookup() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
AddFuncLookup("word", Info{
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
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",
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
Example: "man",
|
|
|
|
|
|
|
|
Output: "string",
|
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
return word(r), nil
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
},
|
|
|
|
})
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|