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

react-ip-details

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-ip-details

Get user location/ip-details/geo position/currency convert based on api or navigation

  • 1.2.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
229
decreased by-42.61%
Maintainers
1
Weekly downloads
 
Created
Source

react-ip-details

Get user location/ip-details/geo position/currency convert based on api or navigation using simple hook on react

Installation

npm install react-ip-details
yarn add react-ip-details

Usage

Here's an example of basic usage:

import React from "react";
import useReactIpLocation from "react-ip-details";

function TimePickerTest() {
  const {
    currency,
    exchangeRate,
    ipResponse,
    exchangeRateResponse,
    errorMessage,
    geoLocationPosition,
    geoLocationErrorMessage,
    currencyString,
  } = useReactIpLocation({ numberToConvert: 100 });
  console.log(`Full ip response ${ipResponse}`);
  console.log(`Full ip exchange-rate response ${exchangeRateResponse}`);
  return (
    <div>
      {`Local currency string format is ${currencyString}`}
      {`Local currency is ${currency}`}
      {`Geo location details: ${geoLocationPosition}`}
      {`Exchange rate is ${exchangeRate}`}
      {`Error Message: ${errorMessage}`}
      {`Geo Error Message: ${geoLocationErrorMessage}`}
    </div>
  );
}

Import Component

import TimePicker from 'react-ip-details'

Props

PropNameTypedefaultdescription
defaultCurrencystringUSDDefault currency (your webpage currency) if u want to make an exchange to local currency
Check currency supported on api used or change url to support it=> https://www.exchangerate-api.com/docs/supported-currencies
detailsByIpUrlstringhttps://geolocation-db.com/json/You can change url to , make sure endpoint return country_code inside response data
exchangeRateUrlstringhttps://api.exchangerate-api.com/v4/latest/You can change url to , make sure ndpoint accept /${currency} addition and return rates in response data
shouldGetIpDetailsbooleantrueWill not use api details request if false.
shouldGetExchangeRatebooleantrueWill not use exchange rate request if false,will keep USD currency only
shouldGetPositionbooleanfalseTurn it to true if u need geolocation info
numberToConvertnumber0If you want to convert number to current currency and format (ex:200 => $100.00(in US) / ALL 10,742(in Albania))
codeCountryToCurrencyobjectjson object (see countryCodeToCurrency.js)You can pass as prop if you want to edit specific country currency for ex : you want to use Eur in Al(Albania)
codeCountryToLocalobjectjson object (see countryCodesToLocal.js)You can pass as prop if you want to edit based on your desire (similar to countryToCurrency)

Return Props

PropNameTypeexampledescription
currencyStringstring$100.00It will return local currency string formated based on currency and exchange rate and numberToConvert
currencystringUSDIt will return local currency based on api at (detailsByIpUrl prop)
exchangeRatestring1.23Exchange rate of default currency to local currency based on ip api and currency exchange api
geoLocationPositionobjectcords: {latitude: 41.342,longitude: 19.811}Get location position based on navigation built in without using api (if you need only this use onlyPosition:true)
ipResponseobjectresponse of api at (endpoint:detailsByIpUrl)
exchangeRateResponseobjectresponse of api at (endpoint:exchangeRateUrl
errorMessagestringMake sure location is allowed by browserIf api fails or anything get wrong it will display messages (messages are static not based on api) replace based on your need
geoLocationErrorMessagestringNo location foundIf navigation location fails to find coords it will display error message

Keywords

FAQs

Package last updated on 18 Mar 2022

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