![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
countries-states-cities-iso2-phone-codes-api
Advanced tools
This will provide all countries, states, cities, ISO2 codes, phone codes, and country flags.
countries-states-cities-iso2-phone-codes-api
is an NPM package that provides an easy-to-use interface to access global data related to countries, including their ISO2 codes, phone codes, states or provinces, and cities. The package allows you to fetch lists of countries, retrieve ISO2 codes by country name, get states by country ISO2 code, and fetch cities within a state.
To install this package, use npm:
npm install countries-states-cities-iso2-phone-codes-api
Below are some examples of how to use the package:
First, require the countries-states-cities-iso2-phone-codes-api
package:
const CountriesAPI = require('countries-states-cities-iso2-phone-codes-api');
Use the getCountryList
method to get the list of all countries with their names:
const countryList = CountriesAPI.getCountryList();
console.log(countryList);
/*
Output:
[
{ name: 'United States' },
{ name: 'Canada' },
{ name: 'Australia' },
// ...other countries
]
*/
You can retrieve a complete list of countries with their ISO2 code and phone code using the getCountries
method:
const countries = CountriesAPI.getCountries();
console.log(countries);
/*
Output:
[
{ name: 'United States', iso2: 'US', phone_code: '+1' },
{ name: 'Canada', iso2: 'CA', phone_code: '+1' },
{ name: 'Australia', iso2: 'AU', phone_code: '+61' },
// ...other countries
]
*/
To retrieve the ISO2 code of a country by its name, use the getIso2ByCountryName
method:
const iso2 = CountriesAPI.getIso2ByCountryName('Canada');
console.log(iso2); // Output: "CA"
Retrieve a list of states or provinces in a specific country by providing the ISO2 code using getStatesByCountry
:
const states = CountriesAPI.getStatesByCountry('US');
console.log(states);
/*
Output:
[
'California',
'Texas',
'New York',
// ...other states
]
*/
To get a list of cities within a specific state of a country, use the getCitiesByState
method by passing the country ISO2 code and state name:
const cities = CountriesAPI.getCitiesByState('US', 'California');
console.log(cities);
/*
Output:
[
'Los Angeles',
'San Francisco',
'San Diego',
// ...other cities
]
*/
You can retrieve the phone code for a country using its ISO2 code with getPhoneCodeByCountry
:
const phoneCode = CountriesAPI.getPhoneCodeByCountry('CA');
console.log(phoneCode); // Output: "+1"
getCountryList()
Returns an array of all countries with their names.
Returns:
Array
: A list of country objects { name: string }
.getCountries()
Returns an array of all countries with their names, ISO2 codes, and phone codes.
Returns:
Array
: A list of country objects { name: string, iso2: string, phone_code: string }
.getIso2ByCountryName(countryName)
Returns the ISO2 code for the given country name.
Arguments:
countryName
(string): The name of the country.Returns:
String
or null
: The ISO2 code if found, otherwise null
.getStatesByCountry(iso2)
Returns an array of states or provinces for the given country ISO2 code.
Arguments:
iso2
(string): The ISO2 code of the country.Returns:
Array
or null
: A list of state names if the country exists, otherwise null
.getCitiesByState(iso2, stateName)
Returns an array of cities for the given state name in the specified country.
Arguments:
iso2
(string): The ISO2 code of the country.stateName
(string): The name of the state or province.Returns:
Array
or null
: A list of city names if the state exists, otherwise null
.getPhoneCodeByCountry(iso2)
Returns the phone code for the given country ISO2 code.
Arguments:
iso2
(string): The ISO2 code of the country.Returns:
String
or null
: The phone code if found, otherwise null
.This package is licensed under the MIT License. See the LICENSE file for more details.
Developed by Masum Billah .
For any issues, suggestions, or contributions, feel free to reach out here.
Feel free to contribute to this repository by submitting issues, suggesting features, or creating pull requests.
FAQs
This will provide all countries, states, cities, ISO2 codes, phone codes, and country flags.
The npm package countries-states-cities-iso2-phone-codes-api receives a total of 5 weekly downloads. As such, countries-states-cities-iso2-phone-codes-api popularity was classified as not popular.
We found that countries-states-cities-iso2-phone-codes-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.