Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Apr 12, 2024
1 parent a901374 commit 25ba795
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/utils/getCountryId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import countries from "../assets/countries.json";
/**
* Get the country id base on the two letter id
*/
export function getCountryId(country: string) {
if (country.length !== 2) {
export function getCountryId(country: string | null) {
if (!country || country.length !== 2) {
return country;
}

const upperCountry = country.toUpperCase();
const countryId = Object.keys(countries).find(
(id) => countries[id].countryCode === upperCountry,
const countryObject = countries.find(
({ countryCode }) => countryCode === upperCountry,
);

if (countryId === undefined) {
if (!countryObject || !countryObject.id) {
return country;
}
return countryId;
return countryObject.id;
}

0 comments on commit 25ba795

Please sign in to comment.