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

countries-lists

v1.0.1

Published

Optimized country, state, city map with lightning query speed

Downloads

15

Readme

Countries Lists

Optimized, lightning-fast country, state, and city map for Node.js.

npm version License: MIT

countries-lists is a comprehensive library providing high-performance access to world countries, states, and cities data. Designed for speed, it uses intelligent caching and lazy-loading strategies to ensure your application remains fast, even when handling large datasets.

Features

  • 🚀 Lightning Fast: Optimized data loading with fs buffers.
  • 📉 Low Memory Footprint: Cities are lazy-loaded only when requested.
  • 📦 Zero Dependencies: Pure data and logic.
  • 📘 TypeScript Ready: Full type definitions included.
  • 🌍 Comprehensive Data: Includes countries, states, and cities with rich metadata (currencies, timezones, lat/long, etc.).
  • 🔍 O(1) Lookups: Indexed access for countries and states.

Installation

npm install countries-lists
# or
pnpm add countries-lists
# or
yarn add countries-lists

Usage

Basic Usage

import { CountryLocalesMap } from 'countries-lists';

// Get all countries (O(N) - cached after first call)
const countries = CountryLocalesMap.getAllCountries();
console.log(countries.length); // 250

// Get a specific country by ISO2 code (O(1))
const us = CountryLocalesMap.getCountryByIso('US');
console.log(us.name); // "United States"
console.log(us.emoji); // "🇺🇸"

// Get States (O(1) lookup)
const states = CountryLocalesMap.getStatesOfCountry(us.id);
console.log(states.length); // 66 (includes territories)

// Get Cities (Lazy loaded on first request)
const ny = states.find(s => s.state_code === 'NY');
if (ny) {
  const cities = CountryLocalesMap.getCitiesOfState(ny.id);
  console.log(cities.length); // 1000+
}

API Reference

CountryLocalesMap

getAllCountries(): Country[]

Returns an array of all available countries.

getCountryByIso(iso2: string): Country | undefined

Returns a country object matching the provided ISO2 code (case-insensitive).

getStatesOfCountry(countryId: number): State[]

Returns all states belonging to a specific country ID.

getCitiesOfState(stateId: number): City[]

Returns all cities belonging to a specific state ID. Warning: This method triggers the loading of the cities dataset if it hasn't been loaded yet.

Data Types

Country

interface Country {
  id: number;
  name: string;
  iso2: string; // e.g., "US"
  iso3: string; // e.g., "USA"
  numeric_code: string;
  phone_code: string; // e.g., "1"
  capital: string;
  currency: string; // e.g., "USD"
  currency_symbol: string; // e.g., "$"
  tld: string; // e.g., ".us"
  region: string;
  subregion: string;
  timezones: Timezone[];
  latitude: string;
  longitude: string;
  emoji: string;
  // ...and more
}

Performance

This package is designed with performance in mind:

  1. Countries & States: Indexed in memory upon first access.
  2. Cities: The largest dataset (~35MB) is not loaded until you explicitely call getCitiesOfState. This allows your service to start up instantly if you only need country/state level data.

License

MIT © Bloxoft