tc39 / ecma402

Status, process, and documents for ECMA 402
https://tc39.es/ecma402/
Other
528 stars 103 forks source link

List of ISO country codes #874

Open jfbrennan opened 4 months ago

jfbrennan commented 4 months ago

I'm looking to avoid maintaining a list of country codes in my app. I would expect JavaScript runtimes to provide this data.

This is precisely what I wish Intl would add to the current supportedValuesOf method:

Intl.supportedValuesOf('region') // "region" key is used in other APIs to mean ISO 3166, i.e. the country codes

Many Intl APIs apparently have mappings for country codes, so perhaps this internal list of codes can be given a public interface (and my apologies if I didn't google hard enough...I spent a lot of time searching around and reading MDN and SO and the tc39 backlogs and didn't find answers).

Why this is needful:

An example:

// List of options for a country select
const names = new Intl.DisplayNames(['en'], {type: 'region'});
const options = Intl.supportedValuesOf('region').map(code => `<option value="${code}">${names.of(code)}</option>`);
sffc commented 4 months ago

Hi, @jfbrennan!

Some initial feedback on your proposal:

select or menu element with a list of countries (e.g. shipping address form)

Probably you can't simply ship to all countries. You probably want to get the list of supported regions from your fulfillment partner.

custom phone number input with list of country prefix numbers (e.g. contacts card phone input)

Seems like this would want to be paired with an additional phone number formatting API.

table of countries and their currency (e.g. financial tools)

The list of countries should probably come from your payment partner, yes?

jfbrennan commented 4 months ago

Defining a list of country codes is not completely trivial.

I understand i18n stuff is tough and standards aren't always 100% reliable, but there is a standard and it should be followed: https://www.iso.org/iso-3166-country-codes.html. All questions about what is included are answered by the standard - the list you get from JavaScript is the list that ISO 3166 defines. So maybe Intl.supportedValuesOf('region') isn't precisely what should be done, perhaps Intl.supportedValuesOf('countrycode').

Not all browsers ship data for all regions.

Yeah, browsers differ. Hasn't stopped the web in the past, shouldn't be a reason to not progress going forward. Define the spec, the rest is left up to implementers 🤞

Questions about your use cases

Let's avoid nitpicking the UX examples - they're just examples.