Lightweight privacy respecting geolocation library with no dependencies.

Overview

tzlocator

Lightweight privacy respecting geolocation library with no dependencies.

Key features

  • πŸ₯‚ No third-party API calls
  • πŸ‘€ Works without browser prompt
  • πŸͺ™ No reverse IP lookups
  • 🌏 Country and currency data
  • πŸ”’ Privacy respecting
  • πŸͺΆ Lightweight with no dependencies
  • πŸŽ“ Fully typed

Installation

// npm
npm install tzlocator
// yarn
yarn add tzlocator
// pnpm
pnpm add tzlocator

Usage

Browser

Single page application

import { Tzlocator, getBrowserTimezone } from "tzlocator"

const tzlocator = new TzLocator()
const location = tzlocator.get(getBrowserTimezone())

Server side rendering

import { getBrowserTimezone } from "tzlocator"

const timezone = getBrowserTimezone()
// send the timezone to the server
document.cookie = `timezone=${timezone};`

Server

import { getRequestCookies } from "my-project"
import { Tzlocator } from "tzlocator"

const tzlocator = new TzLocator()

function getLocation(request: Request) {
	// retrieves the browser's timezone from a cookie
	const cookies = getRequestCookies(request)
	return tzlocator.get(cookies.timezone)
}

Configuration

You can modify tzlocator's configuration by passing an object to its class constructor (e.g. new Tzlocator({})).

{
	include, /*
	An array of functions that take the Tzlocator's `get` method result as a
	parameter and return true if it should be included or false otherwise.
	*/
	exclude, /*
	An array of functions that take the Tzlocator's `get` method result as a
	parameter and return true if it should be excluded or false otherwise
	*/
	fallback, /*
	A string indicating the timezone when the Tzlocator's `get` method can't
	find the given timezone, either because it's not included/excluded or
	because it doesn't exist.
	*/
}

Tzlocator

Used to get the location information (Locator) using a timezone. Can be instanciated with or without a configuration object.

class Tzlocator {
	/**
	 * Returns a boolean indicating if the `timezone` has an assigned
	 * CountryCode.
	 */
	static exists(timezone: string): timezone is Timezone {}

	/**
	 * Returns the Locator corresponding to the `timezone`.
	 * If `useFallback` is true and the `timezone` cannot be found in the
	 * included Locator pool it will return the set config fallback.
	 * Else if there's no set fallback or if `useFallback` is false it will
	 * return undefined.
	 */
	get(timezone: string, useFallback = true) {}

	/**
	 * Returns a boolean indicating if the `timezone` has a valid assigned
	 * Locator.
	 */
	has() {}

	/**
	 * Returns an array of all the valid timezones for the current instance.
	 */
	timezones() {}

	/**
	 * Returns an array of all the valid currencies for the current instance.
	 */
	currencies() {}

	/**
	 * Returns an array of all the valid languages for the current instance.
	 */
	languages() {}

	/**
	 * Returns an array of all the valid locators for the current instance.
	 */
	locators() {}
}

Locator

Location information class. Can be instanciated using a country code (e.g. DE).

class Locator {
	code // country's code
	name: // country's name
	native: // country's native name
	prefix: // country's phone code
	continent: // continent
	measurement: // country's measurement system
	currency: // country's currency information
	locales: // country's locales

	/**
	 * Returns a boolean indicating if the `countryCode` has an assigned
	 * Locator.
	 */
	static exists(countryCode: string): countryCode is CountryCode {}

	/**
	 * Returns the languages corresponding to each locale.
	 */
	getLanguages() {}

	/**
	 * Returns the main locale for this country.
	 */
	getMainLocale() {}

	/**
	 * Returns the main language for this country.
	 */
	getMainLanguage() {}
}

Currency

Currency information class. Can be instanciated using a currency code (e.g. EUR).

class Currency {
	code:  // currency's code
	symbol: // currency's symbol
	name: // currency's name

	/**
	 * Returns a boolean indicating if the `currencyCode` has an assigned
	 * Currency.
	 */
	static exists(currencyCode: string): currencyCode is CurrencyCode {}
}

Language

Language information class. Can be instanciated using a language code (e.g. en).

class Language {
	code: // language's code
	name: // language's name
	native: // language's native name
	scripts: // language's scripts

	/**
	 * Returns a boolean indicating if the `languageCode` has an assigned
	 * Language.
	 */
	static exists(languageCode: string): languageCode is LanguageCode {}
}

Thanks

You might also like...

Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Zero Knowledge Private Voting V1 Motivation On-chain governance today is fully transparent at the cost of privacy. This means that every proposal and

Jun 7, 2022

Eigen ZK-ZKRollup, Low gas-fee, better privacy-enhancement, high composable

Eigen ZK-ZKRollup, Low gas-fee, better privacy-enhancement, high composable

ZKZRU: Eigen ZK-ZKRollup Eigen ZK-ZKRollup provides confidential transaction for users with low gas cost. The ZK-Rollup is an extention of RollupNC an

Dec 22, 2022

YouPeriod.app -- the privacy-first period tracking app

YouPeriod.app The privacy-first period-tracking app. IMPORTANT: This app is still being developed. It's not ready for use yet, but will be soon. Pleas

Dec 17, 2022

There can be more than Notion and Miro. Affine is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

There can be more than Notion and Miro. Affine is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

AFFiNE.PRO The Next-Gen Knowledge Base to Replace Notion & Miro. Planning, Sorting and Creating all Together. Open-source, Privacy-First, and Free to

Jan 9, 2023

πŸ“ŠπŸŒ Super small, light, privacy-focused, self-hostable web statistics provider

πŸ“ŠπŸŒ Super small, light, privacy-focused, self-hostable web statistics provider

femtostats Update: It turns out Fathom Lite does everything I wanted to do except custom events for free, so I'm going to stop working on this for now

Nov 17, 2022

πŸ” A Privacy-first Diff tool for everyone. βœ… Your data never hits our servers.

πŸ” A Privacy-first Diff tool for everyone. βœ… Your data never hits our servers.

Features πŸ” Privacy-first developer tool. πŸ’» Run on your Web Browser, Your data is sent nowhere. πŸ”Ž Find a Difference between two text input for Side

Dec 5, 2022

Always with personal privacy and anonymity in mind.

Clodbunker At the moment we aim to be a cutting-edge service that provides anonymous and secure cloud storage, with a strong focus on end-to-end encry

Mar 15, 2023

Zero dependencies, lightweight, and asynchronous https requests package.

Zero dependencies, lightweight, and asynchronous https requests package.

This project is a Work in Progress and currently in development. The API is subject to change without warning. A small fetching package for super simp

Dec 8, 2022

Simple and lightweight form validation for Svelte with no dependencies.

Svelidate Simple and lightweight form validation for Svelte with no dependencies Installation // npm npm install svelidate // yarn yarn add svelidate

Dec 28, 2022
Simple weather app written in HTML, CSS, and JavaScript using the OpenWeather API for fetching weather and geolocation information

Description Simple weather app written in HTML, CSS, and JavaScript using the OpenWeather API for fetching weather and geolocation information. Acknow

Gleb Korzan 4 Feb 23, 2022
Allows the public to easily report and track the geolocation of anyone or anything they spot outside, using a mobile app or web frontend.

LIVE DEMO: https://armytracker.com/ (tracking the invading Russian army in Ukraine) Attention: - If you'd like to help the project either as a program

Michal Certicky 9 Mar 27, 2022
Lightweight (zero dependencies) library for enabling cross document web messaging on top of the MessageChannel API.

Lightweight (zero dependencies) library for enabling cross document web messaging on top of the MessageChannel API.

LironH 4 Jul 15, 2022
A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

A free and open source resume builder. Go to App What is this app all about? Reactive Resume is a free and open source resume builder that’s built to

Reactive Resume 9.7k Jan 3, 2023
Open source privacy notice design patterns.

Design-first privacy notice template The Juro Privacy Notice is an open source project by https://juro.com and https://stefaniapassera.com/. A couple

Juro 159 Nov 10, 2022
Privacy-focused Google Fonts alternative

Privacy-focused Google Fonts CDN alternative I wrote it in an hour, so please report bugs here. Several improvements could be made here and there, so

coolLabs 245 Dec 27, 2022
DecentraMix.io is a cross-chain, non-custodial, universal privacy-preserving protocol with the decentralized governance

DecentraMix.io is a cross-chain, non-custodial, universal privacy-preserving protocol with the decentralized governance. DecentraWorld applies zkSNARKs to enable transactional privacy for all DeFi components by breaking the on-chain link between depositor and recipient addresses.

DecentraWorld Ecosystem 65 May 7, 2022
Dapp example for airdropping ERC-20 tokens using World ID, preserving privacy for the claimers with zero-knowledge proofs.

World ID Example - Mesha Airdrop This repository contains an example decentralized application (dapp) for World ID. With Mesha Airdrop test airdroppin

Worldcoin 14 Dec 16, 2022
Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Zero Knowledge Private Voting V1 Motivation On-chain governance today is fully transparent at the cost of privacy. This means that every proposal and

Blockchain Capital 18 Dec 16, 2022
Privacy First Toolbox For Developers 🧰

Dev Toolbox ?? A collection of tools for developers in one place Note This project is inspired and shares some code from tooling.one by @egoist which

Nafees Nazik 8 Nov 30, 2022