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 🙏

© 2025 – Pkg Stats / Ryan Hefner

continent-country-map

v1.0.1

Published

[DEPRECATED] A clean, reliable dataset mapping continents to their respective countries using ISO 3166 alpha-2 codes.

Readme

⚠️ DEPRECATED

This package is no longer maintained.

Please use html-entities instead. See: https://www.npmjs.com/package/html-entities


Original README below:


continent-country-map

npm version License: MIT

TypeScript

A modern, well-tested, and developer-friendly TypeScript library providing a clean and reliable dataset mapping continents to their respective countries using ISO 3166-1 alpha-2 codes. Perfect for dashboards, forms, filters, and geolocation-based logic.

Features

  • 🗺️ Comprehensive continent-to-country mapping
  • 🔒 Zero runtime dependencies
  • 📦 Tree-shakable ESM and CommonJS support
  • 🎯 TypeScript-first with full type safety
  • ✅ Thoroughly tested with 100% coverage
  • 🚀 Case-insensitive lookups
  • 📚 Well-documented API

Installation

npm install continent-country-map

Usage

Basic Usage

import {
  continentCountryMap,
  getCountriesByContinent,
  getContinentByCountryCode,
  isValidContinent,
  isCountryInContinent,
} from 'continent-country-map';

// Get all countries in Europe
const europeanCountries = getCountriesByContinent('Europe');
console.log(europeanCountries);
// ['AL', 'AD', 'AT', 'BY', 'BE', ...]

// Get the continent for a country code
const continent = getContinentByCountryCode('US');
console.log(continent);
// 'North America'

// Check if a string is a valid continent name
if (isValidContinent('Europe')) {
  console.log('Valid continent!');
}

// Check if a country belongs to a continent
const isUSInEurope = isCountryInContinent('US', 'Europe');
console.log(isUSInEurope);
// false

Real-world Examples

Form Validation

import { getContinentByCountryCode } from 'continent-country-map';

function validateCountryContinent(countryCode: string, continent: string): boolean {
  const actualContinent = getContinentByCountryCode(countryCode);
  return actualContinent?.toLowerCase() === continent.toLowerCase();
}

// Usage in a form
const isValid = validateCountryContinent('US', 'North America');

Filtering Countries by Continent

import { getCountriesByContinent } from 'continent-country-map';

function filterCountriesByContinent(countries: string[], continent: string): string[] {
  const continentCountries = getCountriesByContinent(continent) || [];
  return countries.filter((country) => continentCountries.includes(country.toUpperCase()));
}

// Usage
const countries = ['US', 'DE', 'FR', 'JP'];
const europeanCountries = filterCountriesByContinent(countries, 'Europe');
// ['DE', 'FR']

Dashboard Continent Selection

import { isValidContinent, getCountriesByContinent } from 'continent-country-map';

function handleContinentSelection(continent: string) {
  if (!isValidContinent(continent)) {
    console.error('Invalid continent selected');
    return;
  }

  const countries = getCountriesByContinent(continent);
  // Update dashboard with country data...
}

API Reference

Data

continentCountryMap

The main data structure mapping continents to their respective country codes.

const map = {
  'Africa': ['DZ', 'AO', 'BJ', ...],
  'Antarctica': ['AQ', 'BV', ...],
  'Asia': ['AF', 'AM', 'AZ', ...],
  // ...
};

Functions

getCountriesByContinent(continentName: string): string[] | undefined

Returns an array of ISO 3166-1 alpha-2 country codes for a given continent.

  • Parameters:
    • continentName: The name of the continent (case-insensitive)
  • Returns: Array of country codes or undefined if continent not found

getContinentByCountryCode(countryCode: string): string | undefined

Returns the continent name for a given country code.

  • Parameters:
    • countryCode: The ISO 3166-1 alpha-2 country code (case-insensitive)
  • Returns: Continent name or undefined if country code not found

isValidContinent(continentName: string): boolean

Type guard that checks if a string is a valid continent name.

  • Parameters:
    • continentName: The string to check
  • Returns: true if the string is a valid continent name

isCountryInContinent(countryCode: string, continentName: string): boolean

Checks if a country belongs to a specific continent.

  • Parameters:
    • countryCode: The ISO 3166-1 alpha-2 country code
    • continentName: The name of the continent
  • Returns: true if the country belongs to the specified continent

Types

type ContinentName =
  | 'Africa'
  | 'Antarctica'
  | 'Asia'
  | 'Europe'
  | 'North America'
  | 'Oceania'
  | 'South America';

type CountryCodeA2 = string; // ISO 3166-1 alpha-2 code

type ContinentCountryMapData = Record<ContinentName, CountryCodeA2[]>;

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT