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: datatype.number and number not
parameter introduced
#1702
Conversation
… and `float` generators.
Somehow it feels like we could try to archive the same in a different/better way |
Not against that idea either. This was my first attempt at this. But if there was a way to apply it more globally that would be helpful too. |
IMO banning a single value isnt that useful usually I omit certain values or values that match or dont match a certain criteria. I think a dedicated method might be useful here. E.g. Not sure about the exact signature yet. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## next #1702 +/- ##
==========================================
- Coverage 99.64% 99.63% -0.01%
==========================================
Files 2240 2240
Lines 240101 240160 +59
Branches 1068 1075 +7
==========================================
+ Hits 239242 239287 +45
- Misses 838 852 +14
Partials 21 21
|
Yes, this is leading in the right direction as equally as I thought about it with my first comment Currently in my head it would look something like this (not tested at all): function exclude(source, filter, options) {
let success = false
let value
do {
value = source(options)
success = filter(value)
} while (!success)
return value
} but as you can see, this is not bound to faker / merseene / seed at all and can be used for anything in JS world |
Team decision We decided that we don't want functions that are not seed dependent in our library. |
Introduced
not
parameter forint
andfloat
number generators.See: https://discord.com/channels/929487054990110771/929487054990110777/1058484035875258419
I had a recurring need to generate numbers with a provided parameter to signify what number I did not want generated.
To prevent endless loops in rare cases with limited runway between min and max parameters, I included a try count with a maximum of hardcoded 100 tries if the number generated is the number
not
wanted. If this were to occur, and error will be thrown as documented.