Fix bug in getCountryLetters

This commit is contained in:
tgpethan 2021-02-07 00:55:27 +00:00
parent 185ef7fd2b
commit 8de96ca8b7

View file

@ -251,12 +251,12 @@ const countryCodes = {
"AI": 7 "AI": 7
} }
module.exports.countryCodes = countryCodes; const countryCodeKeys = Object.keys(countryCodes);
module.exports = { module.exports = {
getCountryID:function(code = "") { getCountryID:function(code = "") {
// Get id of a country from a 2 char code // Get id of a country from a 2 char code
const s = code.toUpperCase(); code = code.toUpperCase();
if (countryCodes[s] != null) return countryCodes[s]; if (countryCodes[s] != null) return countryCodes[s];
else return 0; else return 0;
}, },
@ -264,8 +264,11 @@ module.exports = {
getCountryLetters:function(code) { getCountryLetters:function(code) {
// Get country char code from id // Get country char code from id
for (var i = 0; i < countryCodes.length; i++) { for (var i = 0; i < countryCodes.length; i++) {
if (countryCodes[i] === code) return countryCodes[i]; const countryId = countryCodes[countryCodeKeys[i]];
if (countryId === code) return countryId;
} }
return "XX"; return "XX";
} }
} }
module.exports.countryCodes = countryCodes;