js-user-country
v1.0.1
Published
Get user's country for Javascript projects.
Downloads
1,743
Maintainers
Readme
js-user-country (Get user's country for Javascript projects.)
This library does not use any kind of Geo APIs. Pure browser based solution to detect user's country based on user's timezone. Detects country from user's timezone in browser.
Install
npm install js-user-country --save
Or just include js-user-country.min.js
file.
Example
Initialize:
import getUserCountry from "js-user-country";
console.log(getUserCountry().id); // Prints 'CA'
console.log(getUserCountry().name); // Prints 'Canada'
console.log(getUserCountry().timezones);
/*
Prints:
{
id: 'CA',
name: 'Canada',
timezones: [
'America/Atikokan', 'America/Blanc-Sablon',
'America/Cambridge_Bay', 'America/Coral_Harbour',
'America/Creston', 'America/Dawson',
'America/Dawson_Creek', 'America/Edmonton',
'America/Fort_Nelson', 'America/Glace_Bay',
'America/Goose_Bay', 'America/Halifax',
'America/Inuvik', 'America/Iqaluit',
'America/Moncton', 'America/Montreal',
'America/Nipigon', 'America/Pangnirtung',
'America/Rainy_River', 'America/Rankin_Inlet',
'America/Regina', 'America/Resolute',
'America/St_Johns', 'America/Swift_Current',
'America/Thunder_Bay', 'America/Toronto',
'America/Vancouver', 'America/Whitehorse',
'America/Winnipeg', 'America/Yellowknife'
]
}
*/