faker
faker copied to clipboard
Is there a way to make generated data optional?
Sometimes it is useful to generate randomly optional fields, such as the last name (but really - almost any field).
Is it possible to do something like this:
firstName := faker.FirstName()
lastName := faker.Optional(.5).LastName() // <-- Generate non-empty last name 50% of the time
fullName := firstName
if lastName != "" {
fullName += " " + lastName
}
println("Hello, " + fullName + "!")
Here faker.LastName()
would return empty string 50% of the time.
Is it possible to use a custom generator faker for that?
ref https://github.com/bxcodec/faker/blob/72e522332c49399d4c52a9ad8086244df95f38a6/faker.go#L405-L456