diff --git a/apps/api/src/helper/country.helper.ts b/apps/api/src/helper/country.helper.ts new file mode 100644 index 000000000..9d14d8778 --- /dev/null +++ b/apps/api/src/helper/country.helper.ts @@ -0,0 +1,17 @@ +import { countries } from 'countries-list'; + +export function getCountryCodeByName({ + aliases = {}, + name +}: { + aliases?: Record; + name: string; +}): string { + for (const [code, country] of Object.entries(countries)) { + if (country.name === name || country.name === aliases[name]) { + return code; + } + } + + return undefined; +}