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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@neoskop/privacy-guard.js

v0.1.0

Published

Dependency-free JavaScript library for managing privacy levels on the web. Written in TypeScript.

Downloads

3

Readme

Privacy-Guard.js

Dependency-free JavaScript library for managing privacy levels on the web. Written in TypeScript.

Installation

npm install @neoskop/privacy-guard.js

Basic Usage

Have a look at the demo directory for a complete example.

1. Load the base styles

<link rel="stylesheet" href="privacy-guard.es5.css" />

2. Define the overlay template

<template id="privacy-layer">
  <div class="privacy-layer">
    <div class="privacy-layer__inner">
      <button onClick="guard.hideLayer()" class="privacy-layer__close-button">
        Schließen
      </button>
      <div class="privacy-layer__settings">
        <h2>Levels</h2>
        <button type="button" onClick="guard.selectLevel('basic')">Basic</button>
        <button type="button" onClick="guard.selectLevel('analytics')">Analytics</button>
        <button type="button" onClick="guard.selectLevel('targeting')">Targeting</button>
        <div data-level="basic">
          Active: Basic
        </div>
        <div data-level="analytics">
          Active: Analytics
        </div>
        <div data-level="targeting">
          Active: Targeting
        </div>
      </div>
    </div>
  </div>
</template>

Elements with the data-level attribute are displayed when the corresponding privacy guard level is selected. Otherwise they are hidden.

3. Initialize the Privacy Guard

import PrivacyGuard from '../src/privacy-guard';

const guard = new PrivacyGuard();
guard.init();

API

PrivacyGuard(options?: PrivacyGuardOptions)

Options

interface PrivacyGuardOptions {
  // The name of the cookie that stores the selected privacy guard level
  // Defaults to: "privacy-guard-level"
  cookieName?: string;

  events?: {
    // Callback invoked when the privacy guard level is changed
    onLevelChanged?: (setting: string) => any;
  };

  layer?: {
    // The class name of the overlay container
    // Has to match an element inside the template element
    // Defaults to: "privacy-guard"
    className?: string;

    // Container element the overlay gets appended to
    // Defaults to: document.body
    container?: HTMLElement;

    // Set to true, if you do not want the Privacy Guard to create the overlay
    // Defaults to: false
    disabled?: boolean;

    // The selector for the template element containing the overlay template
    // Defaults to: "#privacy-guard"
    templateSelector?: string;
  };

  // The available privacy guard levels
  // Defaults to: ["basic", "analytics", "targeting"]
  levels?: string[];
}

Methods

const guard = new PrivacyGuard();
  • guard.init(): Initialize the Privacy Guard. Adds the overlay to the DOM.
  • guard.showLayer(): Shows the overlay.
  • guard.hideLayer(): Hides the overlay.
  • guard.selectLevel(level: string): Selects a privacy guard level.