You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

regionist

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regionist

Guesses the user's regional parameters on-device.

6.2.0
latest
Source
npmnpm
Version published
Weekly downloads
12
-33.33%
Maintainers
0
Weekly downloads
 
Created
Source

regionist

Guesses the user's regional parameters on-device.

This library relies on the window object of the user's browser. It guesses timezone, country and the preferred language. It's stateless. Only two methods: guess and match. As there is no %100 accurate way of detecting user's regional parameters, this library tries its chance by combinating the outputs of window.Intl and window.navigator objects.

Install

npm i regionist

or inject with script tag:

<script type="module" src="https://cdn.jsdelivr.net/npm/regionist@7/dist/regionist.iife.js"></script>

<script type="text/javascript">
    console.log(window.Regionist)
</script>

Usage

import { regionist } from 'regionist'
// or
// const { regionist } = require('regionist')

// guess
const guessResult = regionist.guess()

console.assert(guessResult === {
    timezone: 'America/New_York', // timezone name as returned by window.Intl object
    timezoneCountry: 'US', // mapped from the timezone
    preferredLocale: 'tr-TR', // relies on window.navigator
    preferredLanguage: 'tr' // it's just derived from preferredLocale
})

// match, useful for finding the best matching locale against a list of supported locales
const bestLocale = regionist.match(['az-AZ', 'en-US', 'tr-TR'])
console.assert(bestLocale === 'tr-TR') // because user's preferred locale is tr-TR

const bestLocale2 = regionist.match(['az_AZ', 'en_us', 'tr_tr'])
console.assert(bestLocale === 'tr-TR') // always returns formatted

Contributing

If you're interested in contributing, read the CONTRIBUTING.md first, please.

Thanks for the attention 💙 Any amount of support on patreon or github will return you back as bug fixes, new features and bits and bytes.

Keywords

timezone-detection

FAQs

Package last updated on 10 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts