Skip to content

k-yle/get-region

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

get-region

Build Status npm version npm npm bundle size

🌐 Tiny package (<400 bytes!) to get the user's country without calling any APIs, and without hardcoding any data. Works in the browser and nodejs.

It uses the browser's native Intl SDK to get the user's timezone, for example Asia/Shanghai or Europe/Dublin. A different Intl SDK is used to convert the timezone to a country code, such as CN or IE.

It only works in modern browsers that support Intl.Locale#getTimeZones (or the legacy equivalent: Intl.Locale#timeZones).

Example

import region from 'get-region';

console.log(region.country); // for example: ['US'] if you're in the United States

// The API returns an array, but the array will only contain a single country code.
// This may change one day, depending on future geopolitical changes.

Install

npm install get-region

Questions

This library only gives you a country code.

About

🌐 Tiny package (<400 bytes!) to get the user's country without calling any APIs, and without hardcoding any data.

Topics

Resources

License

Stars

Watchers

Forks

Contributors