Skip to content

Commit

Permalink
Ignore postal codes
Browse files Browse the repository at this point in the history
Refs #31
  • Loading branch information
thewilkybarkid committed Jul 11, 2024
1 parent 8cfe993 commit 87c4c31
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lib/Iso3166.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const Alpha2CodeSchema: Schema.Schema<Alpha2Code, string> = Schema.String
export const guessCountry: (location: string) => Option.Option<Alpha2Code> = flow(
String.replaceAll('.', ''),
String.replaceAll(/\((.+?)\)/g, ', $1'),
String.replaceAll(/ [0-9]+/g, ' '),
String.replaceAll(/( and | - )/gi, ', '),
location => Array.prepend(Array.map(location.split(',').reverse(), String.trim), location),
Array.findFirst(location =>
Expand Down
9 changes: 2 additions & 7 deletions test/Iso3166.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('guessCountry', () => {
test.for([
['Algiers ( Algeria)', 'DZ'],
['Baylor College of Medicine, Houston, Texas', 'US'],
['Beijing University of Technology, Beijing 100124, PR China', 'CN'],
['Chicago, IL, USA', 'US'],
['Colorado - United States', 'US'],
['Czech Republic', 'CZ'],
Expand All @@ -30,13 +31,7 @@ describe('guessCountry', () => {
expect(actual).toStrictEqual(Option.some(expected))
})

test.for([
'Beijing University of Technology, Beijing 100124, PR China',
'Fayetteville GA (near Atlanta)',
'Mars',
'Southeast Asia',
'The UK',
])("doesn't guess %s", input => {
test.for(['Fayetteville GA (near Atlanta)', 'Mars', 'Southeast Asia', 'The UK'])("doesn't guess %s", input => {
const actual = _.guessCountry(input)

expect(actual).toStrictEqual(Option.none())
Expand Down

0 comments on commit 87c4c31

Please sign in to comment.