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

react-ip-details

v1.2.6

Published

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

Downloads

3,181

Readme

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

| PropName | Type | default | description | | --------------------- | ------- | ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | | defaultCurrency | string | USD | Default 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 | | detailsByIpUrl | string | https://geolocation-db.com/json/ | You can change url to , make sure endpoint return country_code inside response data | | exchangeRateUrl | string | https://api.exchangerate-api.com/v4/latest/ | You can change url to , make sure ndpoint accept /${currency} addition and return rates in response data | | shouldGetIpDetails | boolean | true | Will not use api details request if false. | | shouldGetExchangeRate | boolean | true | Will not use exchange rate request if false,will keep USD currency only | | shouldGetPosition | boolean | false | Turn it to true if u need geolocation info | | numberToConvert | number | 0 | If you want to convert number to current currency and format (ex:200 => $100.00(in US) / ALL 10,742(in Albania)) | | codeCountryToCurrency | object | json 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) | | codeCountryToLocal | object | json object (see countryCodesToLocal.js) | You can pass as prop if you want to edit based on your desire (similar to countryToCurrency) |

Return Props

| PropName | Type | example | description | | ----------------------- | ------ | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | | currencyString | string | $100.00 | It will return local currency string formated based on currency and exchange rate and numberToConvert | | currency | string | USD | It will return local currency based on api at (detailsByIpUrl prop) | | exchangeRate | string | 1.23 | Exchange rate of default currency to local currency based on ip api and currency exchange api | | geoLocationPosition | object | cords: {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) | | ipResponse | object | response of api at (endpoint:detailsByIpUrl) | | | exchangeRateResponse | object | response of api at (endpoint:exchangeRateUrl | | | errorMessage | string | Make sure location is allowed by browser | If api fails or anything get wrong it will display messages (messages are static not based on api) replace based on your need | | geoLocationErrorMessage | string | No location found | If navigation location fails to find coords it will display error message |