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

geoblock

v1.0.4

Published

A minimal geoblocking library for game websites

Downloads

85

Readme

GeoBlock

A minimal, yet powerful geoblocking library for websites. Easily implement country-based access restrictions with predefined presets for different regulatory contexts.

Features

  • 🌎 Multiple geolocation services with fallbacks
  • 🛡️ Preset country lists for common regulatory scenarios (sanctions, regional restrictions)
  • 🔧 Flexible configuration options
  • 💪 No dependencies
  • 📱 Works in all modern browsers
  • 🎨 Customizable blocking UI
  • ⚡ Lightweight (~5KB minified and gzipped)

Installation

NPM

npm install github:trifle-labs/GeoBlock

Yarn

yarn add github:trifle-labs/GeoBlock

Direct script include

<script src="https://unpkg.com/github:trifle-labs/GeoBlock/dist/geoblock.min.js"></script>

Using with Vite

To use GeoBlock with Vite:

# Install the package
npm install github:trifle-labs/GeoBlock

Then import and use it in your code:

// ESM import for Vite
import GeoBlock from 'geoblock';

// Create an instance and check access
const geoblock = new GeoBlock({
  activePresets: ['sanctions'],
});

// Check and apply blocking if needed
geoblock.checkAndBlock().then((hasAccess) => {
  if (hasAccess) {
    // Initialize your app
  }
});

If you encounter any issues with Vite resolving the package, make sure you're using the latest version of the library and that your Vite configuration is properly set up to resolve node modules.

Basic Usage

// Import the library
import GeoBlock from 'geoblock';

// Create a new instance with default options
const geoblock = new GeoBlock({
  activePresets: ['sanctions'], // Use the sanctions preset
  additionalCountries: ['BR', 'AR'], // Add more countries
  exemptCountries: ['CA'], // Exempt specific countries
});

// Check if the user should be blocked and apply visual blocking if needed
geoblock.checkAndBlock().then((hasAccess) => {
  if (hasAccess) {
    console.log('User has access');
    // Initialize your app here
  } else {
    console.log('User is blocked');
  }
});

Available Presets

The library includes the following built-in presets:

  • sanctions: Countries under international sanctions
  • skillprize: Countries with strict skill-based prize regulations
  • gambling: Countries with strict gambling regulations
  • lottery: Countries with strict lottery regulations
  • raffle: Countries with raffle restrictions

Configuration Options

const geoblock = new GeoBlock({
  // Presets
  presets: {
    // Override or add custom presets
    custom: ['FR', 'DE', 'IT'],
  },

  // Custom descriptions for presets (shown in blocking message)
  presetDescriptions: {
    sanctions: 'International sanctions compliance',
    custom: 'European regulatory restrictions',
    // Override any preset description
  },

  // Which presets to apply (can use multiple)
  activePresets: ['sanctions', 'custom'],

  // Additional individual countries to block (2-letter country codes)
  additionalCountries: ['BR', 'AR'],

  // Countries to exempt from blocking
  exemptCountries: ['CA'],

  // Blocking message (supports {country} and {countryCode} placeholders)
  blockMessage: "We're sorry, access to this site is restricted in {country}.",

  // Legal entity for liability disclaimer (optional)
  legalEntity: 'Company Name Ltd', // If provided, adds liability disclaimer with this entity name

  // Visual blocking settings
  visualBlocking: true,
  blockingClass: 'geo-blocked',
  overlayClass: 'geo-overlay',
  messageClass: 'geo-message',

  // Dismissal options
  allowDismiss: true, // Whether to show the X button to dismiss the notice
  dismissOnOverlayClick: true, // Whether clicking the background dismisses the notice

  // Custom styles for visual elements
  customStyles: {
    overlay: {
      backgroundColor: 'rgba(50, 50, 50, 0.9)',
      backdropFilter: 'blur(5px)',
    },
    message: {
      backgroundColor: '#222',
      color: 'white',
      borderRadius: '20px',
    },
    closeButton: {
      color: '#fff',
      fontSize: '28px',
    },
  },

  // Testing settings
  testMode: false,
  testCountry: null, // Set to a country code to simulate that location
});

API Reference

Constructor

const geoblock = new GeoBlock(options);

Methods

  • async getCountryInfo(): Gets information about the user's country
  • async checkAccess(): Checks if the user should be blocked
  • async checkAndBlock(): Checks access and applies visual blocking if needed
  • applyVisualBlocking(countryData): Manually applies visual blocking
  • removeVisualBlocking(): Removes visual blocking elements
  • getBlockedCountries(): Gets the complete list of blocked countries
  • getPreset(presetName): Gets the country list for a specific preset

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)
  • Opera (latest)
  • Mobile browsers (iOS Safari, Android Chrome)

Development

  1. Clone the repository
  2. Install dependencies: npm install
  3. Run tests: npm test
  4. Build: npm run build
  5. Run example: npm run serve (opens the example in your browser)

License

MIT