Spaces:
Running
Running
File size: 1,582 Bytes
08d905b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
/**
* Extracts country from a conference place string
*/
export function extractCountry(place: string): string | null {
if (!place) return null;
// Extract the last part after the last comma, which is typically the country
const parts = place.split(',');
let country = parts[parts.length - 1].trim();
// Handle special cases like "USA" which might appear in different forms
if (['USA', 'U.S.A.', 'United States', 'United States of America'].includes(country)) {
return 'USA';
}
// Handle "UK" variations
if (['UK', 'U.K.', 'United Kingdom', 'England', 'Scotland', 'Wales'].includes(country)) {
return 'UK';
}
// For places without commas, try to extract known countries
if (parts.length === 1) {
const knownCountries = [
'USA', 'Canada', 'China', 'Japan', 'Germany', 'France', 'UK', 'Italy',
'Spain', 'Australia', 'Brazil', 'India', 'Singapore', 'South Korea',
'Netherlands', 'Sweden', 'Switzerland', 'Belgium', 'Austria', 'Portugal',
'UAE', 'Thailand', 'Hawaii', 'Russia', 'Lithuania'
];
for (const country of knownCountries) {
if (place.includes(country)) {
return country;
}
}
}
return country;
}
/**
* Gets all unique countries from conferences data
*/
export function getAllCountries(conferences: any[]): string[] {
if (!Array.isArray(conferences)) return [];
const countries = new Set<string>();
conferences.forEach(conf => {
if (conf.country) {
countries.add(conf.country);
}
});
return Array.from(countries).sort();
} |