Created
October 29, 2024 12:50
-
-
Save jamespacileo/4b811260eb4e055bbbe7c93a8d8f8ee1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// countryNames.ts | |
import countryNames from './country-names.json'; | |
export function getCommonCountryName(inputName: string): string | undefined { | |
const normalizedInput = inputName.replace(/\s*\(the\)\s*/i, '').trim(); | |
return countryNames[normalizedInput] || undefined; | |
} | |
// countryNames.test.ts | |
import { describe, it, expect } from 'vitest'; | |
import { getCommonCountryName } from './countryNames'; | |
describe('getCommonCountryName', () => { | |
it('should return "United Kingdom" for variants of United Kingdom', () => { | |
expect(getCommonCountryName('United Kingdom')).toBe('United Kingdom'); | |
expect(getCommonCountryName('United Kingdom of Great Britain and Northern Ireland')).toBe('United Kingdom'); | |
expect(getCommonCountryName('United Kingdom (the)')).toBe('United Kingdom'); | |
}); | |
it('should return "Netherlands" for variants of Netherlands', () => { | |
expect(getCommonCountryName('Netherlands')).toBe('Netherlands'); | |
expect(getCommonCountryName('Kingdom of the Netherlands')).toBe('Netherlands'); | |
expect(getCommonCountryName('Netherlands (the)')).toBe('Netherlands'); | |
}); | |
it('should return "United States" for variants of United States', () => { | |
expect(getCommonCountryName('United States')).toBe('United States'); | |
expect(getCommonCountryName('United States of America')).toBe('United States'); | |
expect(getCommonCountryName('United States (the)')).toBe('United States'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment