-
-
Notifications
You must be signed in to change notification settings - Fork 920
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
refactor(location): deprecate zipCode format parameter #3223
base: next
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for fakerjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #3223 +/- ##
==========================================
- Coverage 99.97% 99.96% -0.01%
==========================================
Files 2806 2806
Lines 217156 217168 +12
Branches 982 976 -6
==========================================
- Hits 217092 217088 -4
- Misses 64 80 +16
|
Hmm Given that the default en locale uses the patterns #####, #####-#### I would imagine that a very common case would be forcing 5 digit ZIPs using format:"#####" We might want to provide better guidance for this scenario. |
I'm not sure what you are asking for here. https://github.com/faker-js/faker/blob/ebd0dd04a6055c8878f82c565d6ad13aa34ddd40/src/modules/location/index.ts#L55 I could change the runtime message to include the actual format parameter though: - 'faker.location.zipCode(), faker.location.zipCode({ state }), or faker.helpers.replaceSymbols(format)',
+ `faker.location.zipCode(), faker.location.zipCode({ state }), or faker.helpers.replaceSymbols('${format}')`, I hope the main usecase for that method is without the format parameter using the patterns provided by the locale. Here are some calls using the format parameter.
And without format parameter |
I think my issue is that For example if I have code like const address = [faker.location.streetAddress(), faker.location.city(), faker.location.state(), faker.location.zipCode("#####")].join("\n") I feel to someone reading the code that's more intuitive than a call to say faker.string.numeric() I think "I only want 5 digit zip codes" should be something the zip code method can handle. |
One of the reasons I don't like that pattern is that it focuses on the wrong issue. |
Yes agreed. Having an option where ZIP+4 is only used if an extended:true parameter is used might be good. ZIP+4 is rarely used in practice in the US. |
Unfortunately, I have no clue how the US zip code system works. Other than speeding up international mail delivery (SC) by a week/50% if I use a 9(?) digit zip code instead of the usual 5(?). Does other countries have similar systems? |
ChatGPT says: Most Americans do not know their ZIP+4 code from memory and typically only use the standard five-digit ZIP code in everyday contexts. The ZIP+4 code system is primarily used by the USPS and businesses involved in bulk mailing or shipping, where accuracy and speed are essential. Here’s why ZIP+4 codes are not widely known or commonly used by the general public:
In short, unless a ZIP+4 code is directly needed for business or government purposes, most people only remember and use the five-digit ZIP. |
Do you know any other country that has multiple variants of zip codes? |
Not really. In the UK for example postcodes are like "CB1 1DQ" and in some cases the first part "CB1" might be used to refer to an area like "central Cambridge ". But the default postcode is definitely the long/full one. |
Would I'll lookup our other locale's zip patterns for this as well. |
The question is what is the default. For US zip we want short to be default. But in theory what if there's an another locale where the regular zip code is the long version but there's a short version which is a useful alternative. |
How about: The default is a random one. That way you can check how your system behaves with unexpected values. If you want a specific format you will look up the options and then pick one that you assume does the thing you need. |
First part of #2390
Deprecates the
format
parameter in favor of using the native locale patterns or usingfaker.helpers.replaceSymbols
directly.