🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

country-data-api

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-data-api

Get all country, state, and city data

1.1.3
latest
npm
Version published
Weekly downloads
9
Maintainers
0
Weekly downloads
 
Created
Source

Country Data API

A simple API that provides country, state, and city data. You can retrieve information about countries, their states, cities, and related details using this library.

Features

  • Get a list of all countries.
  • Get country names.
  • Get country details by country name.
  • Get cities by state names.
  • Get states by country name.

Installation

To install the package, run the following command:

npm install country-data-api

Get All Countries
This method returns a list of all countries.


import { getAllCountries } from 'country-data-api';

const countries = getAllCountries();
console.log(countries);

=========================================================

Get All Country Names
This method returns an array of country names.

import { getAllCountryNames } from 'country-data-api';

const countryNames = getAllCountryNames();
console.log(countryNames);

=========================================================

Get Country Details by Country Name
This method returns the details of a country based on its name. If the country is found, it returns the details; otherwise, it returns undefined.

import { getCountryDetailsByName } from 'country-data-api';

const countryDetails = getCountryDetailsByName('Bangladesh');
console.log(countryDetails);

=========================================================

 Get Cities by State Names
 This method allows you to get the list of cities by state names. You can pass a single state name or an array of state names.

 import { getCitiesByStateNames } from 'country-data-api';

// Get cities by a single state name
const citiesInState = getCitiesByStateNames('Dhaka');
console.log(citiesInState);

// Get cities by an array of state names
const citiesInStates = getCitiesByStateNames(['Dhaka', 'Chittagong']);
console.log(citiesInStates);


=========================================================

Get States by Country Name

import { getStatesByCountryName } from 'country-data-api';

const statesInCountry = getStatesByCountryName('Bangladesh');
console.log(statesInCountry);


Keywords

country data

FAQs

Package last updated on 06 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts