Skip to content

Commit

Permalink
Recognise the use of a hyphen rather than a comma
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Jan 7, 2025
1 parent c08bba0 commit ecb5c33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/Iso3166.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const guessCountry: (location: string) => Option.Option<Alpha2Code> = 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 =>
Expand Down
2 changes: 2 additions & 0 deletions test/Iso3166.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand Down

0 comments on commit ecb5c33

Please sign in to comment.