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 🙏

© 2024 – Pkg Stats / Ryan Hefner

country-city-search

v1.0.2

Published

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.

Downloads

22

Readme

Country-City-Search

A Project to get Data about the country cities and states according the request.

Installation

Install country city search with npm

  npm i country-city-search

Features

  • Get all countries names across the world in single array
  • Get exact city using country,state,city name
  • Get All cities in particular state using country name and state name
  • Search city by it's name Get Country details by using country code Get All states from the country by using country code
  • Cross platform usable for frontend and backend

Usage/Examples

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>
    </>
  );
};

Package Enhancement Suggestions

  • Please identify any additional functionalities or data types that would enhance the package.
  • Kindly suggest any further functionalities or data types to be integrated into the package.

Author

Support

For support, email [email protected]

License

MIT