Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvoe committed Dec 5, 2023
2 parents c450282 + 50705d5 commit dbc0519
Show file tree
Hide file tree
Showing 19 changed files with 627 additions and 115 deletions.
93 changes: 39 additions & 54 deletions README.md
@@ -1,6 +1,6 @@
![alt text](https://raw.githubusercontent.com/brianvoe/gofakeit/master/logo.png)

# Gofakeit [![Go Report Card](https://goreportcard.com/badge/github.com/brianvoe/gofakeit)](https://goreportcard.com/report/github.com/brianvoe/gofakeit) ![Test](https://github.com/brianvoe/gofakeit/workflows/Test/badge.svg?branch=master) [![codecov.io](https://codecov.io/github/brianvoe/gofakeit/branch/master/graph/badge.svg)](https://codecov.io/github/brianvoe/gofakeit) [![GoDoc](https://godoc.org/github.com/brianvoe/gofakeit/v6?status.svg)](https://godoc.org/github.com/brianvoe/gofakeit/v6) [![license](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/brianvoe/gofakeit/master/LICENSE.txt)
# Gofakeit [![Go Report Card](https://goreportcard.com/badge/github.com/brianvoe/gofakeit)](https://goreportcard.com/report/github.com/brianvoe/gofakeit) ![Test](https://github.com/brianvoe/gofakeit/workflows/Test/badge.svg?branch=master) [![GoDoc](https://godoc.org/github.com/brianvoe/gofakeit/v6?status.svg)](https://godoc.org/github.com/brianvoe/gofakeit/v6) [![license](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/brianvoe/gofakeit/master/LICENSE.txt)

Random data generator written in go

Expand All @@ -10,7 +10,7 @@ Random data generator written in go

## Features

- [260+ Functions!!!](#functions)
- [310+ Functions!!!](#functions)
- [Random Sources](#random-sources)
- [Global Rand](#global-rand-set)
- [Struct Generator](#struct)
Expand All @@ -24,7 +24,7 @@ Random data generator written in go

## Contributors

Thanks to everyone who has contributed to Gofakeit!
Thank you to all our Gofakeit contributors!

<a href="https://github.com/brianvoe/gofakeit/graphs/contributors">
<img src="https://contrib.rocks/image?repo=brianvoe/gofakeit" />
Expand Down Expand Up @@ -185,14 +185,14 @@ For example, this is useful when it is not possible to modify the struct that yo
// or just return a static value
type CustomString string

func (c *CustomString) Fake(faker *gofakeit.Faker) any {
func (c *CustomString) Fake(faker *gofakeit.Faker) (any, error) {
return CustomString("my custom string")
}

// Imagine a CustomTime type that is needed to support a custom JSON Marshaler
type CustomTime time.Time

func (c *CustomTime) Fake(faker *gofakeit.Faker) any {
func (c *CustomTime) Fake(faker *gofakeit.Faker) (any, error) {
return CustomTime(time.Now())
}

Expand Down Expand Up @@ -266,8 +266,6 @@ fmt.Printf("%s", f.FriendName) // bill
fmt.Printf("%s", f.JumbleWord) // loredlowlh
```



## Templates

Generate custom outputs using golang's template engine [https://pkg.go.dev/text/template](https://pkg.go.dev/text/template).
Expand All @@ -280,7 +278,7 @@ Additional Available Functions
- ToLower(s string) string // Make string lower case
- ToString(s any) // Convert to string
- ToDate(s string) time.Time // Convert string to date
- SpliceAny(args ...any) []any // Build a slice of interfaces, used with Weighted
- SpliceAny(args ...any) []any // Build a slice of anys, used with Weighted
- SpliceString(args ...string) []string // Build a slice of strings, used with Teams and RandomString
- SpliceUInt(args ...uint) []uint // Build a slice of uint, used with Dice and RandomUint
- SpliceInt(args ...int) []int // Build a slice of int, used with RandomInt
Expand Down Expand Up @@ -355,7 +353,7 @@ All functions also exist as methods on the Faker struct

### File

Passing `nil` to `CSV`, `JSON` or `XML` will auto generate data using a random set of generators.
Passing `nil` to `CSV`, `JSON` or `XML` will auto generate data using default values.

```go
CSV(co *CSVOptions) ([]byte, error)
Expand All @@ -365,6 +363,27 @@ FileExtension() string
FileMimeType() string
```

### Template

Passing `nil` will auto generate data using default values.

```go
Template(co *TemplateOptions) (string, error)
Markdown(co *MarkdownOptions) (string, error)
EmailText(co *EmailOptions) (string, error)
FixedWidth(co *FixedWidthOptions) (string, error)
```

### Product

```go
Product() *ProductInfo
ProductName() string
ProductDescription() string
ProductCategory() string
ProductFeature() string
ProductMaterial() string
```

### Person

Expand Down Expand Up @@ -457,9 +476,8 @@ CarTransmissionType() string

### Words

#### Noun

```go
// Nouns
Noun() string
NounCommon() string
NounConcrete() string
Expand All @@ -469,20 +487,14 @@ NounCollectiveAnimal() string
NounCollectiveThing() string
NounCountable() string
NounUncountable() string
```

#### Verb

```go
// Verbs
Verb() string
VerbAction() string
VerbLinking() string
VerbHelping() string
```

#### Adverb

```go
// Adverbs
Adverb() string
AdverbManner() string
AdverbDegree() string
Expand All @@ -491,20 +503,14 @@ AdverbTimeDefinite() string
AdverbTimeIndefinite() string
AdverbFrequencyDefinite() string
AdverbFrequencyIndefinite() string
```

#### Proposition

```go
// Propositions
Preposition() string
PrepositionSimple() string
PrepositionDouble() string
PrepositionCompound() string
```

#### Adjective

```go
// Adjectives
Adjective() string
AdjectiveDescriptive() string
AdjectiveQuantitative() string
Expand All @@ -513,11 +519,8 @@ AdjectiveDemonstrative() string
AdjectivePossessive() string
AdjectiveInterrogative() string
AdjectiveIndefinite() string
```

#### Pronoun

```go
// Pronouns
Pronoun() string
PronounPersonal() string
PronounObject() string
Expand All @@ -526,29 +529,20 @@ PronounReflective() string
PronounDemonstrative() string
PronounInterrogative() string
PronounRelative() string
```

#### Connective

```go
// Connectives
Connective() string
ConnectiveTime() string
ConnectiveComparative() string
ConnectiveComplaint() string
ConnectiveListing() string
ConnectiveCasual() string
ConnectiveExamplify() string
```

#### Word

```go
// Words
Word() string
```

#### Sentences

```go
// Sentences
Sentence(wordCount int) string
Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
LoremIpsumWord() string
Expand Down Expand Up @@ -576,7 +570,7 @@ Dessert() string
```go
Bool() bool
UUID() string
Weighted(options []any, weights []float32)
Weighted(options []any, weights []float32) (any, error)
FlipACoin() string
RandomMapKey(mapI any) any
ShuffleAnySlice(v any)
Expand Down Expand Up @@ -852,14 +846,5 @@ ErrorRuntime() error
### School

```go
school() string
School() string
```

## Template

```go
Template(co *TemplateOptions) (string, error) // Generates custom documents
Markdown(co *MarkdownOptions) (string, error) // Generates markdown documents
EmailText(co *EmailOptions) (string, error) // Generates email documents
FixedWidth(co *FixedWidthOptions) (string, error) // Generates fixed width documents
```
2 changes: 1 addition & 1 deletion address.go
Expand Up @@ -209,7 +209,7 @@ func addAddressLookup() {
latitude: "23.058758",
longitude: "89.022594"
}`,
Output: "map[string]interface",
Output: "map[string]any",
ContentType: "application/json",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
return address(r), nil
Expand Down
2 changes: 1 addition & 1 deletion car.go
Expand Up @@ -76,7 +76,7 @@ func addCarLookup() {
Display: "Car",
Category: "car",
Description: "Random car set of data",
Output: "map[string]interface",
Output: "map[string]any",
ContentType: "application/json",
Example: `{type: "Passenger car mini", fuel: "Gasoline", transmission: "Automatic", brand: "Fiat", model: "Freestyle Fwd", year: "1972"}`,
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand Down
14 changes: 7 additions & 7 deletions csv.go
Expand Up @@ -138,13 +138,19 @@ func addFileCSVLookup() {
Output: "[]byte",
ContentType: "text/csv",
Params: []Param{
{Field: "delimiter", Display: "Delimiter", Type: "string", Default: ",", Description: "Separator in between row values"},
{Field: "rowcount", Display: "Row Count", Type: "int", Default: "100", Description: "Number of rows"},
{Field: "fields", Display: "Fields", Type: "[]Field", Description: "Fields containing key name and function"},
{Field: "delimiter", Display: "Delimiter", Type: "string", Default: ",", Description: "Separator in between row values"},
},
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
co := CSVOptions{}

delimiter, err := info.GetString(m, "delimiter")
if err != nil {
return nil, err
}
co.Delimiter = delimiter

rowcount, err := info.GetInt(m, "rowcount")
if err != nil {
return nil, err
Expand All @@ -169,12 +175,6 @@ func addFileCSVLookup() {
}
}

delimiter, err := info.GetString(m, "delimiter")
if err != nil {
return nil, err
}
co.Delimiter = delimiter

f := &Faker{Rand: r}
csvOut, err := csvFunc(f, &co)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions data/data.go
Expand Up @@ -31,6 +31,7 @@ var Data = map[string]map[string][]string{
"book": Books,
"movie": Movies,
"school": School,
"product": Product,
}

func List() map[string][]string {
Expand Down
64 changes: 64 additions & 0 deletions data/product.go
@@ -0,0 +1,64 @@
package data

var Product = map[string][]string{
"category": {
"electronics", "clothing", "home appliances", "furniture",
"automotive parts", "beauty and personal care", "books", "sports equipment",
"toys and games", "outdoor gear", "pet supplies", "kitchenware",
"health and wellness", "tools and hardware", "office supplies",
"baby products", "jewelry", "home decor", "musical instruments",
"fitness equipment", "mobile phones", "computer accessories", "cameras and photography",
"gardening supplies", "bedding and linens", "food and groceries", "party supplies",
"craft and diy supplies", "camping gear", "watches", "luggage and travel accessories",
"board games", "art supplies", "stationery", "bath and shower products",
"sunglasses", "educational toys", "headphones and earbuds", "sneakers and athletic shoes",
"coffee and tea products", "bicycles and accessories", "cookware", "cosmetics",
"home improvement", "pet food", "laptop bags and cases", "home security systems",
"musical accessories", "skincare products", "smart home devices",
},

"adjective": {
"bold", "swift", "pure", "smart", "fresh",
"cool", "sharp", "zen", "bright", "quick",
"robust", "sleek", "versatile", "innovative", "compact",
"luxe", "modular", "precision", "stream",
},

"name": {
"phone", "laptop", "tablet", "watch", "camera",
"headphones", "speaker", "drone", "car", "bike",
"appliance", "gadget", "tool", "toy", "game",
"computer", "console", "smartwatch", "fitness tracker", "smart home device",
"robot", "router", "television", "smart speaker", "vr headset",
"earbuds", "printer", "mouse", "keyboard", "monitor",
"microwave", "blender", "vacuum", "fan", "toaster",
"clock", "lamp", "shaver", "scale", "thermometer",
"fridge", "oven", "mixer", "iron", "hair dryer",
"fan", "scale", "thermostat", "router", "lightbulb",
},

"feature": {
"wireless", "smart", "eco-friendly", "advanced", "compact",
"high-performance", "energy-efficient", "portable", "durable", "stylish",
"touchscreen", "water-resistant", "noise-canceling", "voice-controlled", "ultra-lightweight",
"multi-functional", "user-friendly", "fast-charging", "biometric", "gps-enabled",
},

"material": {
"titanium", "carbon", "alloy", "bamboo", "leather",
"glass", "ceramic", "aluminum", "stainless", "wood",
"plastic", "rubber", "silicon", "fabric", "paper",
"gold", "silver", "brass", "copper", "bronze",
"chrome", "marble", "granite", "porcelain", "plexiglass",
"quartz", "felt", "suede",
},

"suffix": {
"tech", "pro", "x", "plus", "elite",
"spark", "nexus", "nova", "fusion", "sync",
"edge", "boost", "max", "link", "prime",
"zoom", "pulse", "dash", "connect", "blaze",
"quantum", "spark", "vertex", "core", "flux",
"turbo", "shift", "wave", "matrix",
},
}
2 changes: 1 addition & 1 deletion helpers_test.go
Expand Up @@ -263,7 +263,7 @@ func TestAnyToStringEdgeCases(t *testing.T) {

// Test with a struct containing a nil interface field
type nilInterfaceFieldStruct struct {
Data interface{}
Data any
}
nilInterfaceStruct := nilInterfaceFieldStruct{}
want = `{"Data":null}`
Expand Down

0 comments on commit dbc0519

Please sign in to comment.