faker icon indicating copy to clipboard operation
faker copied to clipboard

Add method to generate a full address

Open matthewmayer opened this issue 2 years ago • 9 comments

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

matthewmayer avatar Apr 02 '23 14:04 matthewmayer

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.

ST-DDT avatar Apr 02 '23 16:04 ST-DDT

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.

ST-DDT avatar Apr 02 '23 16:04 ST-DDT

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.

mylysddp avatar May 14 '23 11:05 mylysddp

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?

mylysddp avatar May 14 '23 11:05 mylysddp

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.

matthewmayer avatar May 14 '23 13:05 matthewmayer

"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.?

mylysddp avatar May 14 '23 13:05 mylysddp

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

dgodonjf avatar Sep 03 '24 18:09 dgodonjf

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

matthewmayer avatar Sep 04 '24 13:09 matthewmayer

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.

matthewmayer avatar Sep 04 '24 13:09 matthewmayer