michaelwittig/node-i18n-iso-countries

make searches by name (getAlpha2Code, getSimpleAlpha2Code, getAlpha3Code, getSimpleAlpha3Code) fail when more than one result is found

Opened this issue · 3 comments

Both the Democratic Republic of the Congo and the Republic of the Congo have "Congo" as a possible name in the English data. While this reflects reality, and both countries are colloquially called "The Congo" or "Congo", the library will always return the first one it encounters. It should probably return both or neither and make the developer do more work, otherwise it's just going to erase one of the two countries in my application.

Hi! Are you referring to the change made in #276 ? According to this logic, the official name must be first, the alias second. The entry for CD should be ["Congo", "Democratic Republic of the Congo"].
Let me know if that addresses your issue.

I mean that this line:

console.log(countries.getAlpha2Code('Congo', 'en'));

logs CG when it could also be CD. Switching which one it returns wouldn't help, because the point is that there isn't a single country with the name "Congo". Returning ['CD', 'CG'] makes sense, throwing makes sense, I do not think returning one or the other is a good idea.

I get your point.