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-info-finder

v1.0.1

Published

This is the NPM for fetch country details

Downloads

18

Readme

country-info-finder

A ReactJS hook to get the country information.

⭐ Support

Liked it? Show your support with a STAR (⭐).

Many Thanks to all the Stargazers who have supported this project with stars (⭐)

Thanks to all stargazers

📦 Installation

You can install the package using npm or yarn:

# npm
npm install country-info-finder

# yarn
yarn add country-info-finder

🚀 Usage

  1. useCountry Hook

Import the package in your app -

import { useCountry } from "country-info-finder";

Get country information using the hook -

const { loading, error, country } = useCountry("Bangladesh");

Example Component : Here is an example of how you can use the useCountry hook in a React component:

import { useCountry } from "country-info-finder";

function App() {
  const { loading, error, country } = useCountry("Bangladesh");

  if (loading) return <p>Loading...</p>;
  if (error) return <p>Error: {error.message}</p>;

  const data = country[0];

  return (
    <div>
      <h1>Country Information</h1>
      <p>
        <strong>Official Name:</strong> {data?.name.official}
      </p>
      <p>
        <strong>Common Name:</strong> {data?.name.common}
      </p>
      <p>
        <strong>Flag:</strong> {data?.flag}
      </p>
    </div>
  );
}

export default App;
  1. useAllCountries Hook

Import the package in your app -

import { useAllCountries } from "country-info-finder";

Get all countries' information from the hook: -

const { loading, error, countries } = useAllCountries();

Example Component : Here is an example of how you can use the useAllCountries hook in a React component:

import { useAllCountries } from "country-info-finder";

function App() {
  const { loading, error, countries } = useAllCountries();

  if (loading) return <p>Loading...</p>;
  if (error) return <p>{error}</p>;

  return (
    <ul>
      {countries.map((country) => (
        <li key={country.cca3}>
          {country.name.common} - {country.flag}
        </li>
      ))}
    </ul>
  );
}

export default App;

🌐 Example Country Data

[
  {
    "name": {
      "common": "Bangladesh",
      "official": "People's Republic of Bangladesh",
      "nativeName": {
        "ben": {
          "official": "বাংলাদেশ গণপ্রজাতন্ত্রী",
          "common": "বাংলাদেশ"
        }
      }
    },
    "tld": [".bd"],
    "cca2": "BD",
    "ccn3": "050",
    "cca3": "BGD",
    "cioc": "BAN",
    "independent": true,
    "status": "officially-assigned",
    "unMember": true,
    "currencies": {
      "BDT": {
        "name": "Bangladeshi taka",
        "symbol": "৳"
      }
    },
    "idd": {
      "root": "+8",
      "suffixes": ["80"]
    },
    "capital": ["Dhaka"],
    "altSpellings": [
      "BD",
      "People's Republic of Bangladesh",
      "Gônôprôjatôntri Bangladesh"
    ],
    "region": "Asia",
    "subregion": "Southern Asia",
    "languages": {
      "ben": "Bengali"
    },
    "translations": {
      "ara": {
        "official": "جمهورية بنغلاديش الشعبية",
        "common": "بنغلاديش"
      },
      "deu": {
        "official": "Volksrepublik Bangladesch",
        "common": "Bangladesch"
      },
      // Additional translations omitted for brevity
    },
    "latlng": [24, 90],
    "landlocked": false,
    "borders": ["MMR", "IND"],
    "area": 147570,
    "demonyms": {
      "eng": {
        "f": "Bangladeshi",
        "m": "Bangladeshi"
      },
      "fra": {
        "f": "Bangladaise",
        "m": "Bangladais"
      }
    },
    "flag": "🇧🇩",
    "maps": {
      "googleMaps": "https://goo.gl/maps/op6gmLbHcvv6rLhH6",
      "openStreetMaps": "https://www.openstreetmap.org/relation/184640"
    },
    "population": 164689383,
    "gini": {
      "2016": 32.4
    },
    "fifa": "BAN",
    "car": {
      "signs": ["BD"],
      "side": "left"
    },
    "timezones": ["UTC+06:00"],
    "continents": ["Asia"],
    "flags": {
      "png": "https://flagcdn.com/w320/bd.png",
      "svg": "https://flagcdn.com/bd.svg",
      "alt": "The flag of Bangladesh has a dark green field bearing a large red circle that is offset slightly towards the hoist side of center."
    },
    "coatOfArms": {
      "png": "https://mainfacts.com/media/images/coats_of_arms/bd.png",
      "svg": "https://mainfacts.com/media/images/coats_of_arms/bd.svg"
    },
    "startOfWeek": "sunday",
    "capitalInfo": {
      "latlng": [23.72, 90.4]
    },
    "postalCode": {
      "format": "####",
      "regex": "^(\\d{4})$"
    }
  }
]

Contributors

We welcome contributions! If you'd like to contribute, please follow these guidelines:

  • Pull Requests: Base your pull requests against the main branch.
  • Contributing Guide: Adhere to the instructions in the contributing guide.
  • Documentation Changes: If your pull request includes changes to the documentation, ensure the README file is updated accordingly.

We appreciate your efforts to improve this project!

License

This project is licensed under the terms of the MIT license.