Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-country-info

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-country-info

use-country-info

  • 1.0.15
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

use-country-info

License

How to works


English-USA

The useCountryInfo hook is a React hook that allows you to easily and efficiently fetch detailed information about countries. With this hook, you can access comprehensive data such as demographic, geographic, and cultural information about any country directly in your React application.

Installation

To use the useCountryInfo hook, you need to have React installed in your project. Run the following command to install the hook:

npm install use-country-info

or

yarn add use-country-info

Usage

Here's a basic example of how to use the useCountryInfo hook in a React component:

import React from 'react';
import { useCountryInfo } from 'use-country-info';

function PageExample() {
  const {
    allCountryInfo,
    ddiInfo,
    countryflags
  } = useCountryInfo();

  // Render the country data or use it as needed
  return (
    <div>
      {allCountryInfo.map((item): any => (
        <p key={item.name?.common}>{item.capital}</p>
      ))}
    </div>
  );
}

export default PageExample;

Objects example


AllCountryInfo
{
    "name": {
      "common": "Jordan",
      "official": "Hashemite Kingdom of Jordan",
      "nativeName": {
        "ara": {
          "official": "المملكة الأردنية الهاشمية",
          "common": "الأردن"
        }
      }
    },
    "tld": [
      ".jo",
      "الاردن."
    ],
    "cca2": "JO",
    "ccn3": "400",
    "cca3": "JOR",
    "cioc": "JOR",
    "independent": true,
    "status": "officially-assigned",
    "unMember": true,
    "currencies": {
      "JOD": {
        "name": "Jordanian dinar",
        "symbol": "د.ا"
      }
    },
    "countryCallingCode": {
      "root": "+9",
      "suffixes": [
        "62"
      ]
    },
    "capital": [
      "Amman"
    ],
    "altSpellings": [
      "JO",
      "Hashemite Kingdom of Jordan",
      "al-Mamlakah al-Urdunīyah al-Hāshimīyah"
    ],
    "region": "Asia",
    "subregion": "Western Asia",
    "languages": {
      "ara": "Arabic"
    },
    "latlng": [
      31,
      36
    ],
    "landlocked": false,
    "borders": [
      "IRQ",
      "ISR",
      "PSE",
      "SAU",
      "SYR"
    ],
    "area": 89342,
    "demonyms": {
      "eng": {
        "f": "Jordanian",
        "m": "Jordanian"
      },
      "fra": {
        "f": "Jordanienne",
        "m": "Jordanien"
      }
    },
    "flag": "🇯🇴",
    "maps": {
      "googleMaps": "https://goo.gl/maps/ko1dzSDKg8Gsi9A98",
      "openStreetMaps": "https://www.openstreetmap.org/relation/184818"
    },
    "population": 10203140,
    "gini": {
      "2010": 33.7
    },
    "fifa": "JOR",
    "car": {
      "signs": [
        "HKJ"
      ],
      "side": "right"
    },
    "timezones": [
      "UTC+03:00"
    ],
    "continents": [
      "Asia"
    ],
    "flags": {
      "png": "https://flagcdn.com/w320/jo.png",
      "svg": "https://flagcdn.com/jo.svg",
      "alt": "The flag of Jordan is composed of three equal horizontal bands of black, white and green, with a red isosceles triangle superimposed on the hoist side of the field. This triangle has its base on the hoist end, spans about half the width of the field and bears a small seven-pointed white star at its center."
    },
    "coatOfArms": {
      "png": "https://mainfacts.com/media/images/coats_of_arms/jo.png",
      "svg": "https://mainfacts.com/media/images/coats_of_arms/jo.svg"
    },
    "startOfWeek": "sunday",
    "capitalInfo": {
      "latlng": [
        31.95,
        35.93
      ]
    },
    "postalCode": {
      "format": "#####",
      "regex": "^(\\d{5})$"
    }
  },

ddiInfo
  {
    "countryCallingCode": {
      "root": "+9",
      "suffixes": [
        "62"
      ]
    },
    "flag": "🇲🇵",
    "flags": {
      "png": "https://flagcdn.com/w320/jo.png",
      "svg": "https://flagcdn.com/jo.svg",
      "alt": "The flag of Jordan is composed of three equal horizontal bands of black, white and green, with a red isosceles triangle superimposed on the hoist side of the field. This triangle has its base on the hoist end, spans about half the width of the field and bears a small seven-pointed white star at its center."
    },
  }

countryflags
  {
    "name": {
      "common": "Jordan",
      "official": "Hashemite Kingdom of Jordan",
    },
    "flag": "🇲🇵",
    "flags": {
      "png": "https://flagcdn.com/w320/jo.png",
      "svg": "https://flagcdn.com/jo.svg",
      "alt": "The flag of Jordan is composed of three equal horizontal bands of black, white and green, with a red isosceles triangle superimposed on the hoist side of the field. This triangle has its base on the hoist end, spans about half the width of the field and bears a small seven-pointed white star at its center."
    },
  }

In the above example, we import the useCountryInfoFetcher hook and use it in the CountryInfo component. The hook returns two variables: allInfo and callingCountries, which contain the information for all countries and the specific information for the calling codes of each country, respectively.

You can use these variables to render the country information in your component or use it as needed.

Contribution

This is an open-source project, and we welcome contributions from the community. If you encounter issues, bugs, or have ideas for improvements, feel free to open an issue or submit a pull request in the official repository on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for more information.



Como usar - Português-BR

O hook useCountryInfo é um hook React que permite obter informações detalhadas sobre países de forma fácil e eficiente. Com este hook, você pode acessar dados abrangentes, como informações demográficas, geográficas e culturais de qualquer país diretamente no seu aplicativo React.

Instalação

Para utilizar o hook useCountryInfo, você precisa ter o React instalado em seu projeto. Execute o seguinte comando para instalar o hook:

npm install use-country-info

ou

yarn add use-country-info

Uso

Aqui está um exemplo básico de como utilizar o hook useCountryInfo em um componente React:

import React from 'react';
import { useCountryInfo } from 'use-country-info';

function PageExample() {
  const {
    allCountryInfo,
    ddiInfo,
    countryflags
  } = useCountryInfo();

  // Render the country data or use it as needed
  return (
    <div>
      {allCountryInfo.map((item): any => (
        <p key={item.name?.common}>{item.capital}</p>
      ))}
    </div>
  );
}

export default PageExample;

Objetos de exemplo


AllCountryInfo
{
    "name": {
      "common": "Jordan",
      "official": "Hashemite Kingdom of Jordan",
      "nativeName": {
        "ara": {
          "official": "المملكة الأردنية الهاشمية",
          "common": "الأردن"
        }
      }
    },
    "tld": [
      ".jo",
      "الاردن."
    ],
    "cca2": "JO",
    "ccn3": "400",
    "cca3": "JOR",
    "cioc": "JOR",
    "independent": true,
    "status": "officially-assigned",
    "unMember": true,
    "currencies": {
      "JOD": {
        "name": "Jordanian dinar",
        "symbol": "د.ا"
      }
    },
    "countryCallingCode": {
      "root": "+9",
      "suffixes": [
        "62"
      ]
    },
    "capital": [
      "Amman"
    ],
    "altSpellings": [
      "JO",
      "Hashemite Kingdom of Jordan",
      "al-Mamlakah al-Urdunīyah al-Hāshimīyah"
    ],
    "region": "Asia",
    "subregion": "Western Asia",
    "languages": {
      "ara": "Arabic"
    },
    "latlng": [
      31,
      36
    ],
    "landlocked": false,
    "borders": [
      "IRQ",
      "ISR",
      "PSE",
      "SAU",
      "SYR"
    ],
    "area": 89342,
    "demonyms": {
      "eng": {
        "f": "Jordanian",
        "m": "Jordanian"
      },
      "fra": {
        "f": "Jordanienne",
        "m": "Jordanien"
      }
    },
    "flag": "🇯🇴",
    "maps": {
      "googleMaps": "https://goo.gl/maps/ko1dzSDKg8Gsi9A98",
      "openStreetMaps": "https://www.openstreetmap.org/relation/184818"
    },
    "population": 10203140,
    "gini": {
      "2010": 33.7
    },
    "fifa": "JOR",
    "car": {
      "signs": [
        "HKJ"
      ],
      "side": "right"
    },
    "timezones": [
      "UTC+03:00"
    ],
    "continents": [
      "Asia"
    ],
    "flags": {
      "png": "https://flagcdn.com/w320/jo.png",
      "svg": "https://flagcdn.com/jo.svg",
      "alt": "The flag of Jordan is composed of three equal horizontal bands of black, white and green, with a red isosceles triangle superimposed on the hoist side of the field. This triangle has its base on the hoist end, spans about half the width of the field and bears a small seven-pointed white star at its center."
    },
    "coatOfArms": {
      "png": "https://mainfacts.com/media/images/coats_of_arms/jo.png",
      "svg": "https://mainfacts.com/media/images/coats_of_arms/jo.svg"
    },
    "startOfWeek": "sunday",
    "capitalInfo": {
      "latlng": [
        31.95,
        35.93
      ]
    },
    "postalCode": {
      "format": "#####",
      "regex": "^(\\d{5})$"
    }
  },

ddiInfo
  {
    "countryCallingCode": {
      "root": "+9",
      "suffixes": [
        "62"
      ]
    },
    "flag": "🇲🇵",
    "flags": {
      "png": "https://flagcdn.com/w320/jo.png",
      "svg": "https://flagcdn.com/jo.svg",
      "alt": "The flag of Jordan is composed of three equal horizontal bands of black, white and green, with a red isosceles triangle superimposed on the hoist side of the field. This triangle has its base on the hoist end, spans about half the width of the field and bears a small seven-pointed white star at its center."
    },
  }

countryflags
  {
    "name": {
      "common": "Jordan",
      "official": "Hashemite Kingdom of Jordan",
    },
    "flag": "🇲🇵",
    "flags": {
      "png": "https://flagcdn.com/w320/jo.png",
      "svg": "https://flagcdn.com/jo.svg",
      "alt": "The flag of Jordan is composed of three equal horizontal bands of black, white and green, with a red isosceles triangle superimposed on the hoist side of the field. This triangle has its base on the hoist end, spans about half the width of the field and bears a small seven-pointed white star at its center."
    },
  }

No exemplo acima, importamos o hook useCountryInfo e o utilizamos no componente CountryInfo. O hook retorna duas variáveis: allInfo e callingCountries, que contêm as informações de todos os países e as informações específicas para os códigos de chamada de cada país, respectivamente.

Você pode utilizar essas variáveis para renderizar as informações dos países no seu componente ou utilizá-las conforme necessário.

Contribuição

Este é um projeto de código aberto, e encorajamos contribuições da comunidade. Se você encontrar problemas, bugs ou tiver ideias para melhorias, fique à vontade para abrir uma issue ou enviar um pull request no repositório oficial do projeto no GitHub.

Licença

Este projeto está licenciado sob a Licença MIT. Consulte o arquivo LICENSE para obter mais informações.

  Este é apenas um exemplo mais elaborado de README.md para o hook `useCountryInfo`. Certifique-se de personalizar e atualizar o conteúdo do arquivo conforme necessário, adicionando seções adicionais relevantes, como exemplos de uso mais avançados, configuração e requisitos de ambiente.

Keywords

FAQs

Package last updated on 20 Jul 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc