Faker Helpers
helpers.* commands are supported in the faker path and are intentionally excluded from the domain abstraction.
Use:
helpers.arrayElement(["red", "green", "blue"])
or:
faker.helpers.arrayElement(["red", "green", "blue"])
Do not use:
domain.helpers.arrayElement(["red", "green", "blue"])
That form is invalid and will fail with helpers_not_supported_in_domain.
Common Helper Examples
helpers.fake("Hi, my name is {{person.firstName}} {{person.lastName}}!")
helpers.mustache("I found {{count}} items.", { count: () => `${this.number.int()}` })
helpers.fromRegExp("[A-Z]{2}[0-9]{3}")
Helper Methods
helpers.arrayElement
helpers.arrayElement(["red", "green", "blue"])
helpers.arrayElements
helpers.arrayElements(["red", "green", "blue"], { min: 1, max: 2 })
helpers.slugify
helpers.slugify("Hello world from AnyWayData")
helpers.replaceSymbols
helpers.replaceSymbols("Order-##??")
helpers.replaceCreditCardSymbols
helpers.replaceCreditCardSymbols("####-####-####-####")
helpers.shuffle
helpers.shuffle(["a", "b", "c"], { inplace: false })
helpers.uniqueArray
helpers.uniqueArray(this.word.sample, 5)
helpers.weightedArrayElement
helpers.weightedArrayElement([{ weight: 5, value: "sunny" }, { weight: 2, value: "rainy" }, { weight: 1, value: "snowy" }])
helpers.rangeToNumber
helpers.rangeToNumber({ min: 1, max: 10 })
helpers.maybe
helpers.maybe(() => "present", { probability: 0.8 }) ?? "fallback"
helpers.multiple
helpers.multiple(() => this.person.firstName(), { count: 3 })
Notes
- Many helper functions can return arrays or objects depending on method and inputs.
- Prefer scalar-returning helpers when using grid/display flows that expect single values.
- Helper methods support callback/object shapes from Faker docs and are intentionally not represented in
domain.*.