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 🙏

© 2025 – Pkg Stats / Ryan Hefner

where-am-i

v0.0.8

Published

Wrapper around several client-side geolocation APIs

Readme

#where-am-i

Simple wrapper around several client-side geolocation APIs

Note - This is still a work in progress!

##Installation

###NPM (for Browserify)

$ npm install --save where-am-i

###Script tag

Just include the dist/where-am-i.min.js file in a script tag on your page.

##Usage

###Via Browserify

var WhereAmI = require('where-am-i')
  , help = new WhereAmI()

help.findMe(
    function (place) {
        // Located successfully!
        console.log(place.lat)
        console.log(place.lng)
        console.log(place.country.name)
    }
  , function (err) {
        // Could not locate!
    }
)

###Via script

<script src="dist/where-am-i.min.js"></script>
<script>
    var help = new WhereAmI()

    help.findMe(
        function (place) {
            // Located successfully!
            console.log(place.lat)
            console.log(place.lng)
            console.log(place.country.name)
        }
      , function (err) {
            // Could not locate!
        }
    )
</script>

UMD is supported for AMD and Node-style module loaders.

###Example

Checkout the example for more usage. You can run the example in your browser like:

$ git clone [email protected]:BenConstable/where-am-i.git
$ cd where-am-i/
$ npm install
$ [node_modules/.bin/]gulp example

##API

####WhereAmI object

#####var w = new WhereAmI([locator], [storage])

The constructor accepts 2 parameters. The first is the geolocation service to use, and the second is the caching backend to use. Both parameters are optional, with sensible defaults.

Available gelocation services:

  • freegeoip (default): Locate via http://freegeoip.net/

Availble caches:

  • localstorage (default): Store the geolocation result in local storage
  • variable: Store the geolocation in a local variable

#####w.findMe(success, error, [fromStorage])

Locate a user. Accepts success and error callbacks, and optionally overriding the option to retrieve the data from storage if it exists (true by default). E.g:

w.findMe(
    function (place) {}
  , function (err) {}
)

#####WhereAmI.addLocatorAdapter(key, service)

Register a new geolocation adapter for use with the service.

The locator should provide locate(success, err) method. See the Free Geo IP adapter for an example.

#####WhereAmI.addStorageAdapter(key, service)

Register a new storage adapter for use with the service.

The storage adapter should provide hasLocated(), putPlace(place) and getPlace() methods. See the local storage adapter for an example.

####Place object

#####p.lat

The geolocated latitude.

#####p.lng

The geolocated longitude.

#####p.country.iso

The geolocated ISO 3166-1 country code (e.g GB).

May be undefined if country could not be determined.

#####p.country.name

The geolocated country name (e.g United Kingdom).

May be undefined if country could not be determined.

#####p.country.region

The geolocated country region. Possible values are:

  • Africa
  • Antarctica
  • Asia
  • Europe
  • North America
  • Oceania
  • South America

May be undefined if country could not be determined.

#####p.inCountry(isoCodes)

Check if the geolocated result is in the given country. Accepts an ISO code, or an array of codes.

If country info is not available, will return false.

#####p.inRegion(regions)

Check if the geolocated result is in the given region (see possible values above). Accepts a single region, or an array of regions. Each region can have an case and any amount of whitespace. E.g:

p.inRegion('North America')
p.inRegion('NORTH AMERICA')
p.inRegion('nOrTHAMerica')
p.inRegion(['North America', 'Europe'])

If country info is not available, will return false.

##License

MIT © Ben Constable