faker
faker copied to clipboard
Configurable global default max int value
Clear and concise description of the problem
currently number.int() upper boundary is Number.MAX_SAFE_INTEGER
such values don't fit in postgres int (max 2147483647)
in our case it's acceptable to generate values with {max: 2147483647} but because a lot of faker data is auto-generated it's not easy to add max value everywhere and where it's possible it leads to repeating same configuration for .int()
Would be great if it would be possible to set global FAKER_MAX_INTEGER value
Suggested solution
add a global configuration option to override Number.MAX_SAFE_INTEGER
Alternative
No response
Additional context
No response
Thank you for your feature proposal.
We marked it as "waiting for user interest" for now to gather some feedback from our community:
- If you would like to see this feature be implemented, please react to the description with an up-vote (:+1:).
- If you have a suggestion or want to point out some special cases that need to be considered, please leave a comment, so we are aware about them.
We would also like to hear about other community members' use cases for the feature to give us a better understanding of their potential implicit or explicit requirements.
We will start the implementation based on:
- the number of votes (:+1:) and comments
- the relevance for the ecosystem
- availability of alternatives and workarounds
- and the complexity of the requested feature
We do this because:
- There are plenty of languages/countries out there and we would like to ensure that every method can cover all or almost all of them.
- Every feature we add to faker has "costs" associated to it:
- initial costs: design, implementation, reviews, documentation
- running costs: awareness of the feature itself, more complex module structure, increased bundle size, more work during refactors
in our case it's acceptable to generate values with
{max: 2147483647}but because a lot of faker data is auto-generated it's not easy to add max value everywhere and where it's possible it leads to repeating same configuration for.int()
Is you feature request for faker.number.int specifically or are you referring to other impacted methods as well?
As a workaround, you could use a helper method:
function uint31() {
return faker.number.int({max: 2147483647});
}
If you look at the method name, then you might already notice, that this covers a very specific use case.
What if you want the entire sint32 range (-2^31 - 2^31 - 1)? Then you would need a FAKER_MIN_INTEGER as well.
What about floats? All the other options in the other methods.
I agree that FAKER_MAX_INTEGER is more likely to be used then most other options, but it is fairly easy to write your own method/workaround to achieve the expected range. Also I assume, that it is more or equally likely to need more than one range, than just uint31.
If we are going to implement it, I would like to have it via config option (v10) rather than an actual global const.
Sorry for returning to this with such delay
Yes, config option is something we can work with
How would you wish such option to look like?
type FakerConfig = {
int: {
defaultMax?: number;
defaultMin?: number;
};
}
or
type FakerConfig = {
defaults: {
// would be quite clean if `int(123)` is not an option 😅
int: Parameters<NumberModule['int']>;
}
}