faker
faker copied to clipboard
Add method to generate a full address
Clear and concise description of the problem
There's no way to generate a "full" address e.g. street, city, state and ZIP together in a locale-aware way.
Different locales write addresses differently, e.g. in some locales you write secondary address before street address, in others vice versa. In some locales you write ZIP code/postcode together with city, in others you write on a seperate line, and some locales dont have ZIPs at all. Some locales go "most to least specific" (e.g. en_US) and some go "least to most specific" (e.g. zh_CN). Some locales utilize the secondary admin area (e.g. county) and some don't.
Suggested solution
Implement faker.location.address() or faker.location.fullAddress() and an associated definition pattern for each locale which might combine some or all of
- streetAddress
- city
- county
- state
- stateAbbr
- zipCode
Alternative
manually construct address from the pieces, but then if you change locales you have to change the pattern.
Additional context
Might need the option to do it as a single line address or multiline
I think we should refer to it for what it used for e.g. fullPostalAddress. Since we don't return dynamic objects it would return a multi line string.
If you are interested in this feature please upvote the top comment, so we know which feature we should focus on. We will consider implementing the feature if it gets enough upvotes.
I have also encountered similar problems. If a complete address cannot be generated, it will lead to a lack of logical relationship between the addresses. For example, the country does not match the state, or the state does not match the city.
Is it possible to add a method to generate complete addresses that allows me to input the name of a country, state, or city, or a postal code, and then generate corresponding city data based on the parameters I pass in?
I think the goal of Faker is to generate plausible-looking rather than necessarily consistent/realistic data.
Making realistic data would require much more complex logic for each country/locale which I think is out of scope of Faker.
"If the data provided is real, the requirements for faker-js will indeed be higher. However, could we consider covering data from several larger countries such as the United States, China, Russia, Canada, etc.?
I get not wanting to push Faker into fully realistic data, but I it would be helpful to better support some basic consistency options similar to how states get filtered by country and how zip code can be filtered by state. A couple of ideas: allow restricting city by state, and provide option to get a state and abbreviated state to align
provide option to get a state and abbreviated state to align
Please upvote https://github.com/faker-js/faker/issues/2349 if you are interested in this
Allow restricting city by state
This is trickier because city names are not necessarily real cities in all locales. In many cases they are patterns like FirstName + suffix eg Matthewville.