43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
|
|
export interface CountryOption {
|
||
|
|
code: string;
|
||
|
|
name: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const COUNTRY_OPTIONS: CountryOption[] = [
|
||
|
|
{ code: "US", name: "United States" },
|
||
|
|
{ code: "CA", name: "Canada" },
|
||
|
|
{ code: "GB", name: "United Kingdom" },
|
||
|
|
{ code: "AU", name: "Australia" },
|
||
|
|
{ code: "DE", name: "Germany" },
|
||
|
|
{ code: "FR", name: "France" },
|
||
|
|
{ code: "IT", name: "Italy" },
|
||
|
|
{ code: "ES", name: "Spain" },
|
||
|
|
{ code: "NL", name: "Netherlands" },
|
||
|
|
{ code: "SE", name: "Sweden" },
|
||
|
|
{ code: "NO", name: "Norway" },
|
||
|
|
{ code: "DK", name: "Denmark" },
|
||
|
|
{ code: "FI", name: "Finland" },
|
||
|
|
{ code: "CH", name: "Switzerland" },
|
||
|
|
{ code: "AT", name: "Austria" },
|
||
|
|
{ code: "BE", name: "Belgium" },
|
||
|
|
{ code: "IE", name: "Ireland" },
|
||
|
|
{ code: "PT", name: "Portugal" },
|
||
|
|
{ code: "GR", name: "Greece" },
|
||
|
|
{ code: "JP", name: "Japan" },
|
||
|
|
];
|
||
|
|
|
||
|
|
const COUNTRY_NAME_BY_CODE = new Map(COUNTRY_OPTIONS.map(option => [option.code, option.name]));
|
||
|
|
const COUNTRY_CODE_BY_NAME = new Map(
|
||
|
|
COUNTRY_OPTIONS.map(option => [option.name.toLowerCase(), option.code])
|
||
|
|
);
|
||
|
|
|
||
|
|
export function getCountryName(code?: string | null): string | undefined {
|
||
|
|
if (!code) return undefined;
|
||
|
|
return COUNTRY_NAME_BY_CODE.get(code) ?? undefined;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getCountryCodeByName(name?: string | null): string | undefined {
|
||
|
|
if (!name) return undefined;
|
||
|
|
return COUNTRY_CODE_BY_NAME.get(name.toLowerCase()) ?? undefined;
|
||
|
|
}
|