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

@bva/ipgeo

Package Overview
Dependencies
Maintainers
5
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bva/ipgeo

A promise based JavaScript wrapper around popular IP Geolocation APIs

  • 2.1.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
5
Weekly downloads
 
Created
Source

IPGeo

IPGeo is a promise based JavaScript wrapper around popular IP Geolocation APIs.

Initial Setup

To setup an instance of IPGeo you'll need to import the library and then create an instance from the IPGeo class.

First add it to your repo:

yarn add @bva/ipgeo

Then use it in your JavaScript:

import IPGeo from "@bva/ipgeo";

const geo = new IPGeo();

geo.getGeo().then(data => console.log(data));

Options

When initializing a new IPGeo instance an optional options argument can be passed to the Class instantiation. The options argument is an Object can have the following properties:

service

Service is the web service you want to use and can be any of the following values:

  • geojs (default) - https://www.geojs.io/
  • ipapi - https://ipapi.co/
  • ... more to come

Methods

getGeo()

This method makes a request to the geo service and returns JSON response wrapped in a promise.

Example

geo.getGeo().then(data => console.log(data));

If using GeoJS the above code will log a JSON object that looks like this. Otherwise, it will log the chosen service's JSON structure.

Note: The first call to .getGeo() will result in an API call which will store the data in sessionStorage under ipgeo. All subsequent calls will pull data from sessionStorage unless it is not supported in the browser.

removeSessionGeoData()

This will remove geo data stored in sessionStorage under ipgeo. If the browser doesn't support it nothing will happen.

Dealing with sessionStorage Data

The data stored in sessionStorage is under the name ipgeo and is base64 encoded. To view the actual data you'll need to decode it using atob().

Example:

console.log(JSON.parse(atob(sessionStorage.getItem("ipgeo"))));

Keywords

FAQs

Package last updated on 16 Oct 2019

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