Skip to content

fix: handle single-character fromRegExp patterns - #3877

Merged
ST-DDT merged 3 commits into
faker-js:nextfrom
hiSandog:fix/from-regexp-single-char-20260601
Jun 10, 2026
Merged

fix: handle single-character fromRegExp patterns#3877
ST-DDT merged 3 commits into
faker-js:nextfrom
hiSandog:fix/from-regexp-single-char-20260601

Conversation

@hiSandog

@hiSandog hiSandog commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • generate a value for a single wildcard pattern instead of returning a literal dot
  • support case-insensitive single-letter RegExp inputs like /w/i
  • enable the existing TODO tests for those cases

Validation

  • pnpm exec vitest run test/modules/helpers.spec.ts
  • pnpm exec eslint src/modules/helpers/index.ts test/modules/helpers.spec.ts

@hiSandog
hiSandog requested a review from a team as a code owner June 1, 2026 11:37
@netlify

netlify Bot commented Jun 1, 2026

Copy link
Copy Markdown

Deploy Preview for fakerjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e02ff21
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a1e46de3d20b90008301491
😎 Deploy Preview https://deploy-preview-3877.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.84%. Comparing base (5bd8709) to head (e02ff21).
⚠️ Report is 1 commits behind head on next.

Files with missing lines Patch % Lines
src/modules/helpers/index.ts 91.17% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3877      +/-   ##
==========================================
- Coverage   98.92%   98.84%   -0.09%     
==========================================
  Files         908      908              
  Lines        3159     3193      +34     
  Branches      581      591      +10     
==========================================
+ Hits         3125     3156      +31     
- Misses         30       33       +3     
  Partials        4        4              
Files with missing lines Coverage Δ
src/modules/helpers/index.ts 94.84% <91.17%> (-0.43%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ST-DDT ST-DDT added c: bug Something isn't working p: 1-normal Nothing urgent m: helpers Something is referring to the helpers module labels Jun 1, 2026
@ST-DDT

ST-DDT commented Jun 1, 2026

Copy link
Copy Markdown
Member

This will cause a merge conflict with #3857

So this may take far longer than usual to merge.

ST-DDT
ST-DDT previously requested changes Jun 1, 2026

@ST-DDT ST-DDT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR only makes the existing rudementary tests green, it does not really implement the feature.

faker.helpers.fromRegExp(/./) // "8"
faker.helpers.fromRegExp(/../) // ".." ❌
faker.helpers.fromRegExp(/w/i) // "W"
faker.helpers.fromRegExp(/ww/i) // "ww" ❌

🏴 BAD-QUALITY: Please ensure PRs are reviewed for quality by humans before submission.

@ST-DDT
ST-DDT marked this pull request as draft June 1, 2026 16:24
@hiSandog

hiSandog commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in d0f1503. The implementation now scans remaining unquantified regex tokens after stripping anchors, replacing repeated wildcard dots like /../ with generated characters and applying case-insensitive generation to repeated literal letters like /ww/i. Added focused regression coverage for both cases and reran helpers.spec.ts.

@ST-DDT
ST-DDT marked this pull request as ready for review June 4, 2026 08:17
@ST-DDT
ST-DDT dismissed their stale review June 4, 2026 08:17

Fixed

@ST-DDT ST-DDT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one issue with the current implementation of the fromRegExp method.
It basically repeats parts of the implementation over and over.
First for unquantified, then for quantified, then for ranges, ...

It fixes the todo, so I think it is an improvement, but it might be worth refactoring/re-implementing it eventually.

@ST-DDT ST-DDT added this to the v10.x milestone Jun 9, 2026
@ST-DDT
ST-DDT added this pull request to the merge queue Jun 10, 2026
Merged via the queue into faker-js:next with commit ec6cc3b Jun 10, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: bug Something isn't working m: helpers Something is referring to the helpers module p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants