npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

country-code-lookup

v0.2.2

Published

Finds countries by various country codes

Readme

NPM version Downloads

Country Code Lookup

A node.js module to look up countries by various country codes.

Supported codes:

  • Legacy FIPS 10-4 / GEC codes (2 letters)
  • ISO 3166 (2 letters)
  • ISO 3166 (3 letters)
  • ISO 3166 (numbers)
  • Internet codes

Installation

$ npm install country-code-lookup

Usage

const lookup = require('country-code-lookup')

// search by FIPS
lookup.byFips('UK')

// search by ISO
lookup.byIso('GB')
lookup.byIso('GBR')
lookup.byIso(826)

// search by internet code
lookup.byInternet('UK')

// search by country name
lookup.byCountry('United Kingdom')

// get an array of all countries
lookup.countries

Searching for a country will return either null, or a country object:

{ continent: 'Europe',
  region: 'Western Europe',
  country: 'United Kingdom',
  capital: 'London',
  fips: 'UK',
  iso2: 'GB',
  iso3: 'GBR',
  isoNo: '826',
  internet: 'UK' }

Invalid inputs and lookup failures

All lookup methods return null when a supported code or exact country name has no matching entry. Country-name matching is case-sensitive and does not trim whitespace.

byFips, byInternet, and byCountry also return null for non-string inputs. byIso returns null for inputs that are neither strings nor numbers.

Numeric ISO inputs must be integers between 0 and 999. Invalid numbers (including negative, fractional, non-finite, and out-of-range values) return null. Digit-only strings are treated as numeric ISO codes, and leading zeros are supported.

Unlike the other lookup methods, byIso throws Error('cannot determine ISO code type') for non-numeric strings whose length is neither two nor three characters. This existing behavior is retained for compatibility.

lookup.byIso('ZZ')       // null: no matching ISO alpha-2 code
lookup.byIso(1826)       // null: numeric code is out of range
lookup.byIso('050')      // Bangladesh
lookup.byCountry(' united kingdom ') // null: not an exact country name
lookup.byIso('invalid')  // throws Error('cannot determine ISO code type')

Country objects expose numeric ISO codes as three-digit strings, such as '004' for Afghanistan. Kosovo has no assigned ISO numeric code, so its isoNo is null.

Data scope and review

Reviewed on 31 October 2026. The dataset contains all 249 current ISO 3166-1 country/territory code triples, checked against UN M49 (plus Taiwan's TW / TWN / 158), and one additional entry for Kosovo. Kosovo's XK / XKX codes are user-assigned conventions, not official ISO assignments. Names generally use common English forms rather than uniformly following formal ISO names.

The retired Netherlands Antilles entry (AN / ANT / 530) has been removed; use Curaçao (CW), Sint Maarten (SX), or Bonaire, Sint Eustatius and Saba (BQ). See IANA's account of the successor codes. Exact country-name lookups now use the updated full names for BQ, SJ, SH, PS, TR, and VI; previous names are not retained as aliases.

FIPS 10-4 was withdrawn in 2008, and its GEC successor was discontinued in 2014. The fips field is retained for legacy lookups, not as a current standard. See NGA's historical registers. The corrected Falkland Islands (FK) and Vietnam (VM) values are also documented in NIST FIPS PUB 10-4 (PDF pages 21 and 55, respectively). An empty fips or internet field means no code is provided; empty-string lookups return null.

Internet codes represent ASCII ccTLD labels without a dot, not a guarantee that a domain is delegated or available for registration. The IANA root database lists delegation status. For example, .um, .bq, .bl, .mf, and .eh are not delegated. UM now identifies the United States Minor Outlying Islands rather than sharing US; IANA explicitly lists .um as eligible but not delegated. Kosovo has no assigned .xk ccTLD, so its internet field is empty.

The capital field is a string, with multiple capitals or administrative centres separated by /. South Africa includes Pretoria, Cape Town, and Bloemfontein; Eswatini includes Mbabane and Lobamba. Sri Lanka lists Sri Jayewardenepura Kotte and its commercial capital, Colombo. The BQ entry lists the three islands' administrative centres, not a single shared capital. Territories without a capital may have an empty string or a descriptive value. These conventions do not distinguish every constitutional capital from a temporary seat of government.

Capital spellings for Georgia, Guatemala, Kazakhstan, Kuwait, Mexico, and Panama are cross-referenced with the UN World Statistics Pocketbook 2026 (printed pages 113, 122, 142, 145, 167, and 192). Its footnotes also describe South Africa's three capitals (page 226) and Sri Lanka's legislative capital (page 229). Kiribati uses the wider South Tarawa designation, as used by the World Bank; the UN profile instead names Bairiki. The three BQ administrative centres are cross-referenced with the Dutch government's island office locations. The full SH territory name follows UK government usage.

Recent capital transitions were checked separately: Equatorial Guinea's 2 January 2026 decree designates Ciudad de la Paz, while Indonesia's Constitutional Court confirmed in May 2026 that Jakarta remains the capital pending a presidential transfer decree. Planned moves are not treated as completed changes.

Geographic fields retain the package's existing regional vocabulary, including Central Africa, Pacific, and ocean-based groupings; they are not a strict implementation of UN M49 regions. Corrected African classifications and the single-continent assignment for transcontinental Russia follow UN M49.

Useful Links

License

MIT