Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
country-city-search
Advanced tools
The process of accessing and utilizing country and city information programmatically, making it a valuable tool for developers working with geographic data in their projects.
A Project to get Data about the country cities and states according the request.
Install country city search with npm
npm i country-city-search
import { getAllCountries, getCitiesByStateAndCountry, getCityByNameAndCountryData, searchCityByName } from "country-city-search";
const Home = () => {
const fetchData = async () => {
//Get All Countries Name with country code in single array
const allCountries = await getAllCountries();
// Output : ['Afghanistan (AF)', 'Albania (AL)',....]
//------------------------------------------------------
//Get City object using city name, state name and country name
const cityObject = await getCityByNameAndCountryData({
cityName: "rajkot",
state_name: "gujarat",
country_name: "India",
});
/*Output :
{
country_code: "IN";
country_id: "101";
country_name: "India";
id: "133679";
latitude: "22.33333000";
longitude: "70.83333000";
name: "Rajkot";
state_code: "GJ";
state_id: "4030";
state_name: "Gujarat";
time_zone_name: "Asia/Kolkata";
wikiDataId: "Q11854";
}
*/
//------------------------------------------------------------
//Get List array of cities object using state and country name
const allCitiesFromState = await getCitiesByStateAndCountry("gujarat", "India");
/*
Output :
[{
"id": "57588",
"name": "Abrama",
"state_id": "4030",
"state_code": "GJ",
"state_name": "Gujarat",
"country_id": "101",
"country_code": "IN",
"country_name": "India",
"latitude": "20.85865000",
"longitude": "72.90648000",
"wikiDataId": "Q490916",
"time_zone_name": "Asia/Kolkata"
}....]
*/
//------------------------------------------------------------
//Search City by it's Name
const city = await searchCityByName("ahmedabad");
/*
Output :
[
{
"id": "57606",
"name": "Ahmedabad",
"state_id": "4030",
"state_code": "GJ",
"state_name": "Gujarat",
"country_id": "101",
"country_code": "IN",
"country_name": "India",
"latitude": "23.02579000",
"longitude": "72.58727000",
"wikiDataId": "Q1070",
"time_zone_name": "Asia/Kolkata"
}, ...
]
*/
//------------------------------------------------------------
//Get country by its Country code
const country = await getCountryByCode("IN");
/*
Output =
[
{
name: "India",
iso3: "IND",
iso2: "IN",
numeric_code: "356",
phone_code: "91",
capital: "New Delhi",
currency: "INR",
currency_name: "Indian rupee",
currency_symbol: "₹",
tld: ".in",
native: "भारत",
region: "Asia",
region_id: "3",
subregion: "Southern Asia",
subregion_id: "14",
nationality: "Indian",
timezones: [...],
translations: {....},
latitude: "20.00000000",
longitude: "77.00000000",
emoji: "🇮🇳",
emojiU: "U+1F1EE U+1F1F3",
}
];
*/
//------------------------------------------------------------
//Get All States List from the country code
const state = await getStatesOfCountry("IN");
/* Output :
[
{
"id": 4023,
"name": "Andaman and Nicobar Islands",
"state_code": "AN",
"latitude": "11.74008670",
"longitude": "92.65864010",
"type": "Union territory"
} ....]
*/
//------------------------------------------------------------
//Get All States List from the country code
const cityies = await getAllCitiesOfState("BDS");
/* Output :
[
{
"id": "52",
"name": "Ashkāsham",
"state_id": "3901",
"state_code": "BDS",
"state_name": "Badakhshan",
"country_id": "1",
"country_code": "AF",
"country_name": "Afghanistan",
"latitude": "36.68333000",
"longitude": "71.53333000",
"wikiDataId": "Q4805192",
"time_zone_name": "Asia/Kabul",
"emoji": "🇦🇫",
"currency_symbol": "؋"
}....]
*/
};
useEffect(() => {
fetchData();
});
return (
<>
<div> Simple Examples for country-city-search package</div>
</>
);
};
For support, email dharmeshpal42@gmail.com
FAQs
The process of accessing and utilizing country and city information programmatically, making it a valuable tool for developers working with geographic data in their projects.
The npm package country-city-search receives a total of 0 weekly downloads. As such, country-city-search popularity was classified as not popular.
We found that country-city-search 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.