Skip to content

Commit

Permalink
Recognise US state codes
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Jan 7, 2025
1 parent b5336d4 commit c08bba0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib/Iso3166.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export const guessCountry: (location: string) => Option.Option<Alpha2Code> = 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(
Expand Down
2 changes: 2 additions & 0 deletions test/Iso3166.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit c08bba0

Please sign in to comment.