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

dom-gdpr-guard

v3.2.0

Published

Vanilla JavaScript binding to use gdpr-guard as efficiently and easily as possible

Downloads

22

Readme

dom-gdpr-guard

Vanilla JavaScript binding to use gdpr-guard as efficiently and easily as possible

This library defines logic to display GDPR settings and allow to easily modify and save them.

If you need any help, you're more than welcome on my official Discord server dedicated to my open-source projects.

You can read the online documentation here and take a look at a very simple example.

How to import

//// ES6
import {
	gdprGuard, // everything that gdpr-guard exports
	// you could also directly import from gdpr-guard as it's a dependency
	render,
	renderInside,
} from "dom-gdpr-guard"

//// Node
const {
	gdprGuard, // everything that gdpr-guard exports
	// you could also directly import from gdpr-guard as it's a dependency
	render,
	renderInside,
} = require("dom-gdpr-guard");

//// Browser
const {
	gdprGuard, // everything that gdpr-guard exports
	render,
	renderInside,
} = window.domGdprGuard;

What's available ?

import { GdprManager } from "gdpr-guard";

declare const renderInside: (target: Element, manager: GdprManager, payload: RenderPayload) => Promise<ReRenderFunction>;

declare const render: (manager: GdprManager, payload: RenderPayload) => Promise<Rendered>;

// render function : (subRenderFunction, savior, gdprItem) => Rendered
declare interface RenderPayload {
	renderManager: ManagerRenderFunction;
	renderGroup: GroupRenderFunction;
	renderGuard: GuardRenderFunction;
}

type Rendered = Element;
type ReRenderFunction = () => Promise<void>;

render

render is a function that allows to render the GDPR state using the provided render functions, manager factory and gdpr savior.

interface GdprRenderResult {
	rendered: Rendered;
	manager: GdprManager;
}

It returns the rendered element so that you can mount it yourself in the DOM. It also returns the manager so that you can query its state for conditional logic.

renderInside

renderInside is a function that allows to render the GDPR state inside a container using the container as well as the provided render functions, manager factory and gdpr savior.

interface ReRenderResult {
	render: ReRenderFunction;
	manager: GdprManager;
}

It returns a function that when called will smartly re-render the GDPR state to avoid the pain of manually handling updates efficiently (it uses DOM diffing). It also returns the manager so that you can query its state for conditional logic.

Savior API

The Savior API is mainly designed for library developers, therefore you might need an additional library to provide with the savior you may need ( e.g. gdpr-guard-local for local storage).

Since v3.0.0, you handle the savior however you wish, it is no longer part of the render API.

Design choices

From a design standpoint, it's been a common trend across all my libraries to expose my APIs as asynchronous if users might need to use their own asynchronous code inside. That comes from the idea that integrating asynchronous code inside code that is required to be synchronous makes it really difficult to interface properly.

As such, even though I use the term return in the previous descriptions, it's more accurate to say that the returned promise resolves to the described value.

That does not mean in any way that you have to return a promise, we can await on non-promise values, and they will resolve immediately. Although, for good measures, if you can mark your functions as async, that would avoid any issues and the code inside would still be the same.

One of the advantages of using promises and asynchronous functions as an API designer is that error handling is "covered for free" with the promises' exception propagation mechanisms.

Changelog

V3.1.0

Fixing the deserialization issues caused by bugged versions of gdpr-guard (updated it to 2.3.0).

V3.0.0

The render API was flawed: it re-generated the manager on every render. As such, a decision was made that the user of this library should get an instance of a GdprManager before rendering. As such, this package is now fully decoupled from the Savior API: it's no longer the render API that calls GdprSavior methods, the user has full control of it.

The fact that you have to have a manager to render also means you can use the Events API from gdpr-guard@^2.2.1 before even rendering anything, which avoids input lags and reduces time-to-first-input.