You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, getCountryCode("Cocos (Keeling) Islands") won't return the correct country code, because of the parentheses in the country name.
Examples or links
The countryName used in the RegExp in the function is not escaped, so characters such as parentheses are interpreted as special characters:
constnameRegex=newRegExp('^'+countryName+'$','i')
The solution in #131 can fix this, or a slight modification:
exportconstgetCountryCode=(countryName: string): TCountryCode|false=>{// Match exact country name, but case insensitiveconst country =countryName.toLowerCase();return(countryDataList.find(({ name, native })=>country===name.toLowerCase()||country===native.toLowerCase())?.iso2||false)}
Maybe allowing something like "Cocos Islands" or "Keeling Islands" also makes sense?
The text was updated successfully, but these errors were encountered:
Hi, forgot about this. Someone could've make a PR :) But looks like no volunteers. I'll check it out and update tests to make sure those countries are found properly.
Use case for the feature
For example,
getCountryCode("Cocos (Keeling) Islands")
won't return the correct country code, because of the parentheses in the country name.Examples or links
The
countryName
used in the RegExp in the function is not escaped, so characters such as parentheses are interpreted as special characters:The solution in #131 can fix this, or a slight modification:
Maybe allowing something like "Cocos Islands" or "Keeling Islands" also makes sense?
The text was updated successfully, but these errors were encountered: