diff --git a/src/lib/Iso3166.ts b/src/lib/Iso3166.ts index d796ec5..de36d08 100644 --- a/src/lib/Iso3166.ts +++ b/src/lib/Iso3166.ts @@ -11,6 +11,8 @@ export const Alpha2CodeSchema: Schema.Schema = Schema.String export const guessCountry: (location: string) => Option.Option = flow( String.replaceAll('.', ''), + String.replaceAll(/\((.+?)\)/g, ', $1'), + String.replaceAll(/( and | - )/gi, ', '), location => Array.prepend(Array.map(location.split(',').reverse(), String.trim), location), Array.findFirst(Option.liftNullable(location => iso3166.getAlpha2Code(location, 'en'))), Option.filter(isAlpha2Code), diff --git a/test/Iso3166.test.ts b/test/Iso3166.test.ts index 409110d..b0d8cef 100644 --- a/test/Iso3166.test.ts +++ b/test/Iso3166.test.ts @@ -4,7 +4,9 @@ import * as _ from '../src/lib/Iso3166.js' describe('guessCountry', () => { test.for([ + ['Algiers ( Algeria)', 'DZ'], ['Chicago, IL, USA', 'US'], + ['Colorado - United States', 'US'], ['Czech Republic', 'CZ'], ['Czechia', 'CZ'], ['GHANA', 'GH'], @@ -22,10 +24,8 @@ describe('guessCountry', () => { }) test.for([ - 'Algiers ( Algeria)', 'Baylor College of Medicine, Houston, Texas', 'Beijing University of Technology, Beijing 100124, PR China', - 'Colorado - United States', 'Fayetteville GA (near Atlanta)', 'London', 'London, Ontario',