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

tz-geo-currency

v1.0.5

Published

A JavaScript library offering an alternative to IP-based geolocation, using timezone information to infer a user's country and currency.

Downloads

1,996

Readme

tz-geo-currency

npm Build Status License

A JavaScript library offering an alternative to IP-based geolocation, using timezone information to infer a user's country and currency.

see Motivation

Installation

Using NPM

npm install tz-geo-currency

Using Yarn

yarn add tz-geo-currency

Usage

getCountry()

Outputs the most probable user's country (in ISO 3166-1 alpha-2) based on timezone, e.g., get 'US' if TZ is America/New_York.

For the accuracy and limitations, see FAQ

import { TL } from 'tz-geo-currency'; // TL stands for TimeLocate

const country = TL.getCountry(); // 'US'

getCountries()

Outputs an array of all possible countries based on timezone

const countries = TL.getCountries(); //['US'], assume the TZ is same

getCurrencies()

Outputs an array of currency codes (in ISO 4217) of the most probable country, which derived from timezone

const currencies = TL.getCurrencies(); // ['USD'], assume the TZ is same

getCurrenciesFromCountry(countryCode: string)

Outputs an array of currency codes on given country

const currencies = TL.getCurrenciesFromCountry('JP'); // ['JPY']

FAQ

How accurate is TL.getCountry()?

TL.getCountry() is at least 89% accurate. Use TL._reportAccuracy() to see specific stats and understand its accuracy for your needs. In cases where your application doesn't encounter complex timezones, the accuracy may align closely with IP Geolocation methods (which is around 99%).

Here's the brief output of TL._reportAccuracy() from latest version.

{
  accuracy: 89.42307692307693,
  inaccurateList: [
    [ 'Africa/Abidjan', [Array] ],
    [ 'Africa/Johannesburg', [Array] ],
    [ 'Africa/Lagos', [Array] ],
    [ 'Africa/Maputo', [Array] ],
    [ 'Africa/Nairobi', [Array] ],
    [ 'America/Panama', [Array] ],
    [ 'America/Phoenix', [Array] ],
    [ 'America/Puerto_Rico', [Array] ],
    [ 'America/Toronto', [Array] ],
    [ 'Asia/Bangkok', [Array] ],
    [ 'Asia/Dubai', [Array] ],
    [ 'Asia/Kuching', [Array] ],
    [ 'Asia/Qatar', [Array] ],
    [ 'Asia/Riyadh', [Array] ],
    [ 'Asia/Singapore', [Array] ],
    [ 'Asia/Yangon', [Array] ],
    [ 'Europe/Belgrade', [Array] ],
    [ 'Europe/Berlin', [Array] ],
    [ 'Europe/Brussels', [Array] ],
    [ 'Europe/Helsinki', [Array] ],
    [ 'Europe/London', [Array] ],
    [ 'Europe/Paris', [Array] ],
    [ 'Europe/Prague', [Array] ],
    [ 'Europe/Rome', [Array] ],
    [ 'Europe/Simferopol', [Array] ],
    [ 'Europe/Zurich', [Array] ],
    [ 'Indian/Maldives', [Array] ],
    [ 'Pacific/Auckland', [Array] ],
    [ 'Pacific/Guadalcanal', [Array] ],
    [ 'Pacific/Guam', [Array] ],
    [ 'Pacific/Pago_Pago', [Array] ],
    [ 'Pacific/Port_Moresby', [Array] ],
    [ 'Pacific/Tarawa', [Array] ]
  ]
}

Note that it might still work if the user's timezone is in inaccurateList. Since getCountry will return the first country in the IANA TZ dataset, which is the country of most-populous city compared to other's

What metadata is supported?

Currently, the library identifies country and currency. We're focused on reliably providing these key details. With the country code, you can easily fetch more specific metadata as needed for your application.

Motivation

In 2024, it remains not straightforward for global web applications to automatically detect users' countries and currencies, which are essential for processing payments and customizing product displays. The Geolocation API, while capable of accurately locating users, is often considered too invasive for the mere purpose of content localization, as it requires user consent upon page load.

The Standard: IP Geolocation

Traditionally, services use IP geolocation to identify user locations, linking IP addresses to physical locations for precise localization. While effective, it introduces challenges related to complexity and cost associated with maintaining accurate IP geolocation databases.

A Streamlined Alternative: Timezone-Based Detection

An alternative, inspired by a Stack Overflow suggestion, leverages timezone information to infer countries and currencies. This method, bypassing the need for extensive databases, simplifies implementation and reduces operational costs.

Trade-offs to Consider

  • Privacy: Unlike IP geolocation, timezone detection doesn't handle sensitive data, offering a discreet localization method.
  • Accuracy: IP geolocation is more accurate, directly associating users with locations. Timezone-based detection, less precise, is still practical for applications where exact localization isn't critical.
  • Cost and Simplicity: The timezone method is straightforward and avoids the costs related to IP geolocation services, making it an economical choice for broad use.