Skip to content

feat: add exclude option to faker.helpers.enumValue - #3959

Open
hazrid93 wants to merge 1 commit into
faker-js:nextfrom
hazrid93:hazrid93/82_2994
Open

feat: add exclude option to faker.helpers.enumValue#3959
hazrid93 wants to merge 1 commit into
faker-js:nextfrom
hazrid93:hazrid93/82_2994

Conversation

@hazrid93

Copy link
Copy Markdown

Closes #2994.

Add an optional exclude option (enumValue(enumObject, { exclude: [...] })): values in exclude are not eligible to be picked. If exclude removes every enum value, a FakerError is thrown. The default behavior (no exclude / empty exclude) is unchanged.

@hazrid93
hazrid93 requested a review from a team as a code owner July 20, 2026 10:44
@netlify

netlify Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploy Preview for fakerjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 81487f2
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a5e27bb8f1a63000890ef1d
😎 Deploy Preview https://deploy-preview-3959.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.

ST-DDT
ST-DDT previously requested changes Jul 20, 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.

CI is failing. Please run pnpn run preflight before commiting.

@ST-DDT
ST-DDT marked this pull request as draft July 20, 2026 11:57
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.88%. Comparing base (9ce88ce) to head (81487f2).
⚠️ Report is 1 commits behind head on next.

Files with missing lines Patch % Lines
src/modules/helpers/module.ts 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3959      +/-   ##
==========================================
- Coverage   98.91%   98.88%   -0.03%     
==========================================
  Files         923      924       +1     
  Lines        3223     3228       +5     
  Branches      567      587      +20     
==========================================
+ Hits         3188     3192       +4     
- Misses         31       32       +1     
  Partials        4        4              
Files with missing lines Coverage Δ
src/modules/helpers/module.ts 94.61% <83.33%> (-0.24%) ⬇️

... and 2 files with indirect coverage changes

🚀 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.

Closes faker-js#2994.

Add an optional `exclude` option (`enumValue(enumObject, { exclude: [...] })`): values in `exclude` are not eligible to be picked. If exclude removes every enum value, a FakerError is thrown. The default behavior (no exclude / empty exclude) is unchanged.
@ST-DDT
ST-DDT marked this pull request as ready for review July 20, 2026 13:58
@ST-DDT
ST-DDT requested a review from Copilot July 20, 2026 13:58
@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent s: pending triage Pending Triage m: person Something is referring to the person module labels Jul 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends faker.helpers.enumValue to support excluding specific enum values from selection, aligning the helper with common seeding/use-case needs (e.g., avoiding a particular enum member during generation).

Changes:

  • Added an optional options parameter with exclude to filter out ineligible enum values before selection.
  • Added a dedicated error path when no enum values remain after applying exclude.
  • Updated JSDoc to document the new option and thrown error condition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1104 to +1108
.filter((key) => !exclude.includes(enumObject[key] as T[keyof T]));
if (keys.length === 0) {
throw new FakerError(
'No enum value is available to pick from after applying the exclude option.'
);
/**
* The values to exclude when picking.
*/
exclude?: Array<T[keyof T]>;
Comment on lines +1100 to +1106
const exclude = options?.exclude ?? [];
// ignore numeric keys added by TypeScript
const keys: Array<keyof T> = Object.keys(enumObject).filter((key) =>
Number.isNaN(Number(key))
);
const keys: Array<keyof T> = Object.keys(enumObject)
.filter((key) => Number.isNaN(Number(key)))
.filter((key) => !exclude.includes(enumObject[key] as T[keyof T]));
if (keys.length === 0) {
throw new FakerError(
@ST-DDT
ST-DDT dismissed their stale review August 9, 2026 16:12

Stale

@ST-DDT

ST-DDT commented Aug 9, 2026

Copy link
Copy Markdown
Member

Could you please address the feedback provided by copilot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: feature Request for new feature m: person Something is referring to the person module p: 1-normal Nothing urgent s: pending triage Pending Triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add exclude on enum faker.helpers.enumValue

3 participants