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

@tansuasici/country-state-city

v2.0.10

Published

Complete world countries, states, and cities data in JSON, CSV, XML, and YAML formats. Modern UI components included.

Downloads

200

Readme

Country State City

A modern web application and API platform built with Next.js 15 and TypeScript, providing comprehensive location data for 250+ countries, 5,000+ states, and 150,000+ cities worldwide.

Next.js TypeScript HeroUI License

🌟 Features

  • 🌍 Complete Global Coverage: 250+ countries, 5,000+ states, 150,000+ cities
  • 📊 Multiple Data Formats: JSON, CSV, XML, and YAML support
  • 🎨 Modern UI: Built with HeroUI components and Tailwind CSS
  • ⚡ Fast Performance: Optimized API responses under 100ms
  • 🔍 Advanced Search: Powerful filtering and search capabilities
  • 📱 Responsive Design: Mobile-first approach with dark mode support
  • 🔧 RESTful API: Comprehensive API endpoints
  • 📦 NPM Package: Easy integration with your projects
  • 🛡️ ISO Standards: ISO 3166-1 compliant country codes

📋 Prerequisites

  • Node.js 18.0 or later
  • npm or yarn package manager

📚 API Documentation

Sample API Endpoints

# Get all countries
GET /api/countries

# Get states by country ID
GET /api/countries/231/states

# Get cities by state ID  
GET /api/states/1416/cities

# Search with filters
GET /api/countries?search=united&limit=10

Example Response

{
  "success": true,
  "data": [
    {
      "id": 231,
      "name": "United States",
      "iso2": "US",
      "iso3": "USA",
      "capital": "Washington",
      "currency": "USD",
      "emoji": "🇺🇸"
    }
  ],
  "total": 1,
  "page": 1,
  "limit": 10
}

📦 NPM Package

Install our NPM package for easy integration:

npm install @tansuasici/country-state-city

Basic Usage

import { CountryStateCity } from '@tansuasici/country-state-city';

// Get all countries
const countries = CountryStateCity.getAllCountries();

// Get country by ID
const country = CountryStateCity.getCountryById(231);

// Get country by ISO code
const usa = CountryStateCity.getCountryByIso2('US');
const turkey = CountryStateCity.getCountryByIso3('TUR');

// Get states by country
const states = CountryStateCity.getStatesByCountryId(231);

// Get cities by state
const cities = CountryStateCity.getCitiesByStateId(1416);

// Search functionality
const searchResults = CountryStateCity.searchCountries('United');
const stateResults = CountryStateCity.searchStates('California', 231);
const cityResults = CountryStateCity.searchCities('New York', null, 231);

Export Data in Different Formats

import { CountryStateCity } from '@tansuasici/country-state-city';

// Export as JSON (default)
const countriesJson = CountryStateCity.getAllCountries();

// Export as CSV
const countriesCsv = CountryStateCity.getAllCountries('csv');

// Export as XML
const statesXml = CountryStateCity.getStatesByCountryId(231, 'xml');

// Export as YAML
const citiesYaml = CountryStateCity.getCitiesByStateId(1416, 'yaml');

All Available Methods

Country Methods

// Get all countries
CountryStateCity.getAllCountries(format?: 'json' | 'csv' | 'xml' | 'yaml');

// Get country by ID
CountryStateCity.getCountryById(id: number);

// Get country by ISO2 code (e.g., 'US')
CountryStateCity.getCountryByIso2(iso2: string);

// Get country by ISO3 code (e.g., 'USA')
CountryStateCity.getCountryByIso3(iso3: string);

// Search countries by name
CountryStateCity.searchCountries(query: string);

// Get countries by region (e.g., 'Asia', 'Europe')
CountryStateCity.getCountriesByRegion(region: string);

// Get countries by subregion (e.g., 'Western Europe')
CountryStateCity.getCountriesBySubregion(subregion: string);

State Methods

// Get all states
CountryStateCity.getAllStates(format?: 'json' | 'csv' | 'xml' | 'yaml');

// Get state by ID
CountryStateCity.getStateById(id: number);

// Get states by country ID
CountryStateCity.getStatesByCountryId(countryId: number, format?: string);

// Get states by country code
CountryStateCity.getStatesByCountryCode(countryCode: string, format?: string);

// Search states
CountryStateCity.searchStates(query: string, countryId?: number);

City Methods

// Get all cities (use with caution - large dataset)
CountryStateCity.getAllCities(format?: 'json' | 'csv' | 'xml' | 'yaml');

// Get city by ID
CountryStateCity.getCityById(id: number);

// Get cities by state ID
CountryStateCity.getCitiesByStateId(stateId: number, format?: string);

// Get cities by country ID
CountryStateCity.getCitiesByCountryId(countryId: number, format?: string);

// Search cities
CountryStateCity.searchCities(query: string, stateId?: number, countryId?: number);

Utility Methods

// Get statistics
CountryStateCity.getStats();
// Returns: { countries: 250, states: 5000, cities: 150000 }

// Get all regions
CountryStateCity.getAllRegions();
// Returns: ['Africa', 'Americas', 'Antarctica', 'Asia', 'Europe', 'Oceania']

// Get all subregions
CountryStateCity.getAllSubregions();
// Returns: ['Caribbean', 'Central America', 'Central Asia', ...]

// Get all timezones
CountryStateCity.getAllTimezones();
// Returns: ['Africa/Abidjan', 'Africa/Accra', ...]

// Get all currencies
CountryStateCity.getAllCurrencies();
// Returns: [{ code: 'USD', name: 'US Dollar', symbol: '$' }, ...]

// Export data in specific format
CountryStateCity.exportData(
  dataType: 'countries' | 'states' | 'cities',
  format: 'json' | 'csv' | 'xml' | 'yaml',
  options?: FormatOptions
);

TypeScript Support

The package includes full TypeScript support with type definitions:

import { 
  CountryStateCity,
  Country,
  State,
  City,
  DataFormat,
  FormatOptions
} from '@tansuasici/country-state-city';

// Type-safe operations
const country: Country | undefined = CountryStateCity.getCountryById(231);
const states: State[] = CountryStateCity.getStatesByCountryId(231) as State[];
const cities: City[] = CountryStateCity.getCitiesByStateId(1416) as City[];

🧪 Testing

# Run development server
npm run dev

# Build for production
npm run build

# Start production server
npm start

# Lint code
npm run lint

⚖️ License

This project is licensed under the MIT License.

🙏 Acknowledgments

  • Data sources and contributors
  • Open source community
  • HeroUI team for the excellent component library