Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return faker.helpers.fromRegExp() for strings where string pattern is provided #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tmiddlehurst
Copy link

@tmiddlehurst tmiddlehurst commented Oct 17, 2024

Extend transform string logic to return faker's fromRegExp() if a regexp pattern is provided, e.g.

percent_change:
    type: string
    pattern: '/[0-9]{2}.[0-9]{2}/'
email_address:
    type: string
    pattern: '/[a-z]{5,15}@springfieldnuclear.org/'

Useful for cases where you want to return a random stringified number within certain parameters, e.g.

faker.helpers.fromRegExp(/[0-9]{2}.[0-9]{2}/)                  // "55.11"
faker.helpers.fromRegExp(/[a-z]{5,15}@springfieldnuclear.org/) // homerjsimpson@springfieldnuclear.org  

https://fakerjs.dev/api/helpers#fromregexp

@tmiddlehurst tmiddlehurst changed the title Return faker fromRegExp where string pattern is provided Return faker.helpers.fromRegExp() for strings where string pattern is provided Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant