From ecb5c33069bb41d7fce48335f7ee24f22a87348c Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Tue, 7 Jan 2025 14:43:05 +0000 Subject: [PATCH] Recognise the use of a hyphen rather than a comma --- src/lib/Iso3166.ts | 1 + test/Iso3166.test.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/lib/Iso3166.ts b/src/lib/Iso3166.ts index 5584f93..bf3a06b 100644 --- a/src/lib/Iso3166.ts +++ b/src/lib/Iso3166.ts @@ -22,6 +22,7 @@ export const guessCountry: (location: string) => Option.Option = flo String.replaceAll(/\((.+?)\)/g, ', $1'), String.replaceAll(/ [0-9]+/g, ' '), String.replaceAll(/( and | - )/gi, ', '), + String.replaceAll(/([a-z]+)[-–]([a-z]+)/gi, '$1, $2, $&'), String.replaceAll(/(^| )(the|near|greater) /gi, ''), location => Array.prepend(Array.map(location.split(',').reverse(), String.trim), location), Array.findFirst(location => diff --git a/test/Iso3166.test.ts b/test/Iso3166.test.ts index 5dbd320..005461f 100644 --- a/test/Iso3166.test.ts +++ b/test/Iso3166.test.ts @@ -14,6 +14,7 @@ describe('guessCountry', () => { ['Colorado - United States', 'US'], ['Czech Republic', 'CZ'], ['Czechia', 'CZ'], + ['Dallas-Fort Worth', 'US'], ['Düsseldorf', 'DE'], ['Fayetteville GA (near Atlanta)', 'US'], ['GHANA', 'GH'], @@ -23,6 +24,7 @@ describe('guessCountry', () => { ['London, Ontario', 'CA'], ['London, UK', 'GB'], ['London, United Kingdom', 'GB'], + ['Nairobi-Kenya', 'KE'], ['New York City and Los Angeles', 'US'], ['Norwich', 'GB'], ['Québec', 'CA'],