Given an enumeration such as:
enum DistributionType {
Calculated = "Calculated",
Custom = "Custom",
None = "None",
}
How do I use Faker.JS to pick a random enum value from it?
const randomValue = faker.???
Reference: https://fakerjs.dev/
For @faker-js/faker > 8.0.0 you can now also use the following helper:
const randomValue = faker.helpers.enumValue(DistributionType);
I ended up doing this, as I didn't see any specific helpers for enums.
const randomValue = faker.helpers.arrayElement(Object.values(DistributionType));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With