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

country-atlas

v1.1.1

Published

A lightweight, production-ready, type-safe country data library providing ISO standards, currencies, flags, timezones, calling codes, and map-ready geographic metadata for 250+ countries.

Readme

🌍 Country Atlas

npm version npm downloads license TypeScript bundle size

Production-ready, type-safe, and tree-shakable country metadata for modern applications.

Country Atlas is a comprehensive country intelligence package designed for validation, localization, mapping, phone handling, and UI use cases. It works equally well in frontend and backend environments, ships with zero runtime dependencies, and is optimized for performance.


✨ Key Features

  • 🧩 Fully type-safe – Strict TypeScript types with literal ISO codes for complete autocomplete support
  • 🚩 Native Name Lookup – Find countries by their native names (e.g., "भारत", "République française")
  • 🌲 Tree-shakable – Import only what you need (regions, utilities, or single lookups)
  • 🚫 Zero runtime dependencies – Pure data + utilities
  • 🚩 Infinite-scale flags – Optimized SVG flags that scale without quality loss
  • 📞 Phone intelligence – Validation, parsing, formatting, and country auto-detection
  • 🎨 Flag image utilities – Resize, shape, filter, and convert SVG flags
  • 🌍 Geographic helpers – Neighbors, bounds, lat/lng, and distance calculation
  • 🧪 Well tested – 160+ tests validating data integrity, performance, and utilities
  • 🔄 CI/CD ready – Automated workflows for testing, build verification, and linting

📦 Installation

npm install country-atlas
# or
yarn add country-atlas
# or
pnpm add country-atlas

🚀 Quick Start

Basic Lookup

import { getCountryByISO2, getCountryByName } from 'country-atlas';

const india = getCountryByISO2('IN'); // Full autocomplete for ISO codes!
console.log(india?.name); // India
console.log(india?.currency.code); // INR
console.log(india?.flag.emoji); // 🇮🇳

const usa = getCountryByName('united states');
console.log(usa?.iso.alpha3); // USA

// Native Name Lookup
const bharat = getCountryByName('भारत');
console.log(bharat?.name); // India

🔍 Search & Filtering

import {
    searchCountry,
    getCountriesByContinent,
    getCountryByCallingCode,
    getCountriesByCurrency,
} from 'country-atlas';

const matches = searchCountry('uni');
const asia = getCountriesByContinent('Asia');
const us = getCountryByCallingCode('+1');
const euroZone = getCountriesByCurrency('EUR');

import { getBorderCountries } from 'country-atlas';
const neighbors = getBorderCountries('India'); // Returns array of Country objects

⚡ Performance-Oriented Access

Fetch only the fields you need:

import { getCountry } from 'country-atlas';

const minimal = getCountry('FR', {
    fields: ['name', 'capital', 'currency'],
});

📋 Exported Constants

Access raw metadata lists directly for select components or dropdowns:

import { CONTINENTS, ISO2_CODES, ISO3_CODES, CURRENCY_CODES } from 'country-atlas';

console.log(CONTINENTS); // ['Asia', 'Europe', ...]
console.log(ISO2_CODES); // ['AF', 'AX', 'AL', ...]

📞 Phone Number Utilities

import { utils } from 'country-atlas';

const result = utils.validatePhoneNumber('+1-202-555-0123', 'US');
console.log(result);
/*
{
  isValid: true,
  country: 'US',
  nationalNumber: '2025550123',
  internationalFormat: '+1 202 555 0123',
  callingCode: '+1'
}
*/

utils.isValidPhoneNumber('+44 20 7946 0958', 'GB'); // true
utils.getCountryFromPhoneNumber('+33 1 42 86 82 00'); // France
utils.formatPhoneNumberInternational('2025550123', 'US');
utils.parsePhoneNumber('+1-202-555-0123');

🚩 Flag Image Manipulation

import { getCountryByISO2, utils } from 'country-atlas';

const country = getCountryByISO2('US');
const flagSvg = country?.flag.svg;

utils.resizeFlagSvg(flagSvg, 320, 240);
utils.resizeFlagSvgMaintainRatio(flagSvg, 200, 200);
utils.resizeFlagWithPreset(flagSvg, 'SMALL'); // 32x24
utils.applyFlagShape(flagSvg, 'circle', 64);
utils.applyFlagFilter(flagSvg, { grayscale: 100 });
utils.svgToDataUrl(flagSvg);
utils.generateFlagImgTag(flagSvg, {
    width: 64,
    height: 48,
    alt: 'United States Flag',
});

🌍 Region-Based Imports (Tree-Shaking)

import { asia } from 'country-atlas';

console.log(asia.length); // 50+ countries

🖥️ CLI Usage

# Look up by code or name (India, IN, IND)
npx atlas lookup IN

# List neighboring countries
npx atlas borders "United Kingdom"

# Search with table output (default)
npx atlas search "United"

# Get machine-readable JSON
npx atlas lookup US --json

# List countries by region
npx atlas region Asia

🧱 Data Model (Simplified)

interface Country {
    name: string;
    officialName: string;
    iso: {
        alpha2: string;
        alpha3: string;
        numeric: string;
    };
    geo: {
        continent: string;
        region: string;
        latlng: [number, number];
        bounds?: [number, number, number, number];
        placeId?: string;
    };
    currency: {
        code: string;
        name: string;
        symbol: string;
    };
    flag: {
        emoji: string;
        svg: string;
    };
}

🧪 Testing & Quality

The package includes 163 comprehensive tests using Vitest to ensure:

  • 36 tests - Image manipulation & flag utilities
  • 30 tests - Phone number validation
  • 46 tests - Utility functions (validators, formatters, guards, sorting, geo)
  • 27 tests - API functions (Indexing, Native Lookup, Borders)
  • 17 tests - CLI functionality (Tables, JSON, Borders)
  • 7 tests - Data integrity, schema validation, search
# Run all tests (157 tests in ~4s)
npm test

# Run fast unit tests only (141 tests in ~325ms)
npm run test:unit

# Run CLI tests only
npm run test:cli

# Watch mode for development
npm run test:watch

Performance: Unit tests execute in 325ms for rapid development feedback!


📚 Data Sources

  • ISO 3166-1 – Country codes
  • Unicode CLDR – Locale and formatting data
  • mledoze/countries – Core country metadata
  • lipis/flag-icons – High-quality SVG flags

📄 License

ISC © Prathin Sajith