From 87c4c3186f6bc61df1f651fd48afcbfe9778003a Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Thu, 11 Jul 2024 11:50:36 +0100 Subject: [PATCH] Ignore postal codes Refs #31 --- src/lib/Iso3166.ts | 1 + test/Iso3166.test.ts | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib/Iso3166.ts b/src/lib/Iso3166.ts index 6c2a01e..9317d7d 100644 --- a/src/lib/Iso3166.ts +++ b/src/lib/Iso3166.ts @@ -15,6 +15,7 @@ export const Alpha2CodeSchema: Schema.Schema = Schema.String export const guessCountry: (location: string) => Option.Option = 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 => diff --git a/test/Iso3166.test.ts b/test/Iso3166.test.ts index 4fb70a8..705a83f 100644 --- a/test/Iso3166.test.ts +++ b/test/Iso3166.test.ts @@ -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'], @@ -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())