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

ledger-geoip

v0.9.2

Published

Find the geoip information for an IP address, do so using a list of geoip reporters that is weighted over time.

Downloads

67

Readme

ledger-geoip

Find the geoip information for an IP address, do so using a list of geoip reporters that is weighted over time.

API

Get the Country Code for your IP address

    var getGeoIP = require('ledger-geoip').getGeoIP

    getGeoIP(function (err, provider, result) {
      if (err) return console.log((provider ? (provider.name + ': ') : '') + err.toString())

      console.log('provider=' + provider.name + ' satoshis=' + result)
    })

This method works by using a modified round-robin algorithm with a simple scoring system:

  • each time that getGeoIP is called, it shuffles the list of providers and then orders them according to each provider's score

  • each provider is tried in order and the first (successful) result is returned

  • if the attempt is successful, then the provider's score is set to a number between -250 and 5000 that corresponds to the number of milli-seconds it to took to round-trip and process the request

  • if the attempt fails, then the provider score is set to one of:

    • on DNS (or other network) error: -350;

    • on timeout: -500;

    • HTTP error: -750; or,

    • on internal error: -1001 (thereby disqualifying the provider from further consideration)

Add to the list of Providers

Each of these properties is mandatory:

    require('ledger-geoip').providers.push({ name     : 'commonly-known name of provider'
                                           , site     : 'https://example.com/'
                                           , server   : 'https://api.example.com'
                                           , path     : '"/v1/address" + address'
                                           , addressP : true
                                           , textP    : false
                                           , iso3166  : 'body.country_code'
                                           })

The default value for the method is "GET"; (or "POST" if the value for the payload property is present).

Both the mandatory path property and the optional payload property are evaluated with this context:

    { address: '...' }

where address is either the first argument to the getGeoIP function, or is determined by calling whatIsMyIP. The context is initialize only if the optional addressP property is set to true.

The mandatory iso3166 property is evaluated with this context:

    { body: JSON.parse(HTTP_response_body) }

or

    { lines: HTTP_response_body.split('\n') }

depending on whether the optional textP property is present and set to true.

Finally...

All of the GeoIP reporters in this package are available using public APIs without any API key.

If you want to have your GeoIP reporter added to the package, please send an email to Brave Software.

If you want to have your GeoIP reporter removed from the package, also send an email.

Enjoy!