You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

21 lines
377 B

import { countries } from 'countries-list';
export function getCountryCodeByName({
aliases = {},
name
}: {
aliases?: Record<string, string>;
name: string;
}): string {
if (aliases[name]) {
return aliases[name];
}
for (const [code, country] of Object.entries(countries)) {
if (country.name === name) {
return code;
}
}
return undefined;
}