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

feat(number): bigint multipleOf #3402

Open
wants to merge 29 commits into
base: next
Choose a base branch
from

Conversation

soc221b
Copy link

@soc221b soc221b commented Feb 16, 2025

Adds the multipleOf option to faker.number.bigInt():

@soc221b soc221b requested a review from a team as a code owner February 16, 2025 05:33
Copy link

netlify bot commented Feb 16, 2025

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit c563103
🔍 Latest deploy log https://app.netlify.com/sites/fakerjs/deploys/67c31a35a13d740008460b8c
😎 Deploy Preview https://deploy-preview-3402.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent m: number Something is referring to the number module labels Feb 16, 2025
@ST-DDT ST-DDT added this to the vAnytime milestone Feb 16, 2025
@ST-DDT ST-DDT requested a review from a team February 16, 2025 08:57
Copy link

codecov bot commented Feb 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.97%. Comparing base (f591459) to head (c563103).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3402   +/-   ##
=======================================
  Coverage   99.97%   99.97%           
=======================================
  Files        2811     2811           
  Lines      216972   216982   +10     
  Branches      944      951    +7     
=======================================
+ Hits       216917   216929   +12     
+ Misses         55       53    -2     
Files with missing lines Coverage Δ
src/modules/number/index.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@ST-DDT
Copy link
Member

ST-DDT commented Feb 16, 2025

Thanks for your contribution. ❤️
I'll look at it more closely soon.
Have a nice weekend

@ST-DDT
Copy link
Member

ST-DDT commented Feb 18, 2025

I finally had some time to look into you PR and run some tests locally.
I found a few cases that behave differently from the existing methods:

faker.number.int({ 'min': 6, 'max': 9, 'multipleOf': 5 }) // Error: No suitable integer value between 6 and 9 found.
faker.number.bigInt({ 'min': 6, 'max': 9, 'multipleOf': 5 }) // 10
faker.number.int({ 'min': -9, 'max': 0, 'multipleOf': 5 }) // -5
faker.number.bigInt({ 'min': -9, 'max': 0, 'multipleOf': 5 }) // Error: Multiple of 5n should be less than or equal to max 0n.

Please fix these cases and add tests for them.

@soc221b soc221b marked this pull request as draft February 22, 2025 04:59
@soc221b soc221b marked this pull request as ready for review February 22, 2025 06:42
Copy link
Member

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

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

Sorry, for the slow review. It looks good to me, just a few suggestions to make it easier to read.

const delta = max - min;
if (effectiveMax < effectiveMin) {
throw new FakerError(
`No suitable bigint value between ${min} and ${max} found.`
Copy link
Member

Choose a reason for hiding this comment

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

@faker-js/maintainers @faker-js/members
Not sure about this one. BigInt or bigint?

Suggested change
`No suitable bigint value between ${min} and ${max} found.`
`No suitable BigInt value between ${min} and ${max} found.`

If we change it here, we should also change it in the jsdocs above.

@soc221b
Copy link
Author

soc221b commented Mar 1, 2025

Sorry, for the slow review. It looks good to me, just a few suggestions to make it easier to read.

Thank you for your review. I have made the changes you suggested.

@ST-DDT ST-DDT requested a review from a team March 1, 2025 10:56
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: number Something is referring to the number module p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants