Skip to content
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

Help: append countryCode as country #978

Open
sweidac opened this issue Feb 10, 2025 · 2 comments
Open

Help: append countryCode as country #978

sweidac opened this issue Feb 10, 2025 · 2 comments

Comments

@sweidac
Copy link
Contributor

sweidac commented Feb 10, 2025

Hi again 👋 ,

I played around a little but couldn't find a way to use the country-code instead of the country inside the formatted adress.
There is one similar case in the examples, but that is using { abbreviate: true, countryCode: 'UK' } which replaces 7 countries, depending on src/templates/abbreviations.json (at least I'm assuming that).

I'd want to avoid the path of replacing the country inside the formatted address.

@JirkaChadima
Copy link
Collaborator

hi, that's what the abbreviate: true does. It uses additional configuraiton from the file. Can you describe more what would be your expected result? I'd need to take a look back at the code to understand what it's supposed to do and why it does what it does and not what you expect it to do.

@sweidac
Copy link
Contributor Author

sweidac commented Feb 18, 2025

I'd want the spelled out country to be abbreviated with it's countryCode:

it('first', () => {
  const formatted = addressFormatter.format({
    "houseNumber": 301,
    "road": "Hamilton Avenue",
    "neighbourhood": "Crescent Park",
    "city": "Palo Alto",
    "postcode": 94303,
    "county": "Santa Clara County",
    "state": "California",
    "country": "United States of America",
    "countryCode": "US",
  }, {
    useCountryCodeInsteadOfCountry: true
  });

  expect(formatted).toBe(
`301 Hamilton Avenue
Palo Alto, CA 94303
USA
`);

// instead of 
expect(formatted).not.toBe(
`301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
`);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants