From c08bba088cd62746b42cc504bea92f9f11a7734d Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Tue, 7 Jan 2025 14:21:15 +0000 Subject: [PATCH] Recognise US state codes --- src/lib/Iso3166.ts | 8 ++++++++ test/Iso3166.test.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/lib/Iso3166.ts b/src/lib/Iso3166.ts index 3a8ca12..5584f93 100644 --- a/src/lib/Iso3166.ts +++ b/src/lib/Iso3166.ts @@ -37,6 +37,14 @@ export const guessCountry: (location: string) => Option.Option = flo subDivision => subDivision.country, ), ), + Option.orElse(() => + location.length === 2 + ? Option.map( + Array.findFirst(subDivisions, subDivision => subDivision.code === `US-${location}`), + subDivision => subDivision.country, + ) + : Option.none(), + ), Option.orElse(() => Option.map( Array.matchLeft( diff --git a/test/Iso3166.test.ts b/test/Iso3166.test.ts index 9cf041c..5dbd320 100644 --- a/test/Iso3166.test.ts +++ b/test/Iso3166.test.ts @@ -5,6 +5,8 @@ import * as _ from '../src/lib/Iso3166.js' describe('guessCountry', () => { test.for([ ['Algiers ( Algeria)', 'DZ'], + ['Athens', 'GR'], + ['Athens, GA', 'US'], ['Baylor College of Medicine, Houston, Texas', 'US'], ['Beijing University of Technology, Beijing 100124, PR China', 'CN'], ['Brasil', 'BR'],