Getting started
country-kit is a TypeScript dataset of the 249 assigned ISO 3166-1 codes. Look up a country, search by name or TLD, read a calling code, or fetch a flag URL. No runtime dependencies.
Install
Section titled “Install”Node 18 or newer. ESM and CommonJS.
First lookup
Section titled “First lookup”getCountry accepts an alpha-2 code (US), alpha-3 (USA), or numeric / UN M49 code (840 or 84). Unknown values return undefined.
Try queries on the playground.
Country record
Section titled “Country record”name is the ISO 3166-1 English short name. commonName is the everyday label for a select or heading.
Kosovo (XK) is not in the dataset. It is user-assigned, not ISO 3166-1 assigned. Field sources: data.
Calling code vs dial prefix
Section titled “Calling code vs dial prefix”NANP members share the E.164 country code +1. dialCode adds the primary area code so a phone input can show +1264 for Anguilla.
Show dialCode in a picker. Store callingCode when you want the ITU-T country code.
The core package stores a version-pinned CDN URL. Import country-kit/flags only if you need inline SVG markup.
Browse every flag on flags.
TypeScript
Section titled “TypeScript”isValidCountryCode is a type guard for the CountryCode union. getCountry also accepts alpha-3 and numeric codes.
Copy-paste widgets are on Examples. The full function list is on API. Browse all 249 records in Explorer. The 1.x calling-code change is in the changelog.