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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rafaelcostapalma/consent

v0.2.0

Published

Framework-agnostic cookie/data consent manager (LGPD/GDPR) with a vanilla core and pluggable integrations (Google Consent Mode included).

Readme

@rafaelcostapalma/consent

A cookie/data consent banner for sites that need to comply with LGPD (Brazil) or GDPR (EU): show a banner before any non-essential cookie or tracking script runs, let visitors accept, reject, or choose by category, and remember that choice. Blocks Google Analytics, Meta Pixel, chat widgets, or any other third-party script until the matching category is granted — including tags that live inside a single Google Tag Manager container, via a built-in Google Consent Mode integration.

Framework-agnostic, zero runtime dependencies, config-driven (categories, copy, and links all come from the config object you pass in — nothing hardcoded for one specific site). Built to be reused across multiple client sites rather than rewritten per project.

Cookie consent banner example

Works two ways:

  • Bundler / Next.js: import { init } from '@rafaelcostapalma/consent'
  • Plain HTML, no build step: <script src=".../dist/browser.global.js">, exposes window.MKConsent

Install

npm install @rafaelcostapalma/consent

Usage (ESM / Next.js)

import { init, has, open } from '@rafaelcostapalma/consent';
import '@rafaelcostapalma/consent/style.css';
import { googleConsentMode } from '@rafaelcostapalma/consent/integrations/google-consent-mode';

init({
  storageKey: 'mkconsent',
  version: 1,
  categories: [
    { id: 'necessary', required: true, label: 'Necessários', description: '...' },
    { id: 'analytics', label: 'Analytics', description: '...' },
    { id: 'marketing', label: 'Marketing', description: '...' }
  ],
  texts: {
    title: 'Nós usamos cookies',
    description: '...',
    policyLabel: 'Política de Privacidade',
    policyHref: '/privacidade'
  },
  integrations: [googleConsentMode({})]
});

If you're gating a GTM container, also inline the Consent Mode bootstrap (googleConsentModeBootstrap()) as the very first thing in <head>, before the GTM loader script — it can't be a normal import, since Consent Mode defaults must exist before GTM has a chance to fire any tag.

That alone isn't enough, though: each tag inside GTM (GA4, Ads, Meta Pixel) needs its own Consent Settings configured in the Tag Manager UI to actually check these signals — see docs/gtm-consent-setup.md for the click-by-click steps and how to verify it before publishing.

Usage (plain HTML, no build step)

<link rel="stylesheet" href="/vendor/consent/consent.css">
<script src="/vendor/consent/browser.global.js"></script>
<script>
  MKConsent.init({ /* same config shape as above */ });
</script>

Gating arbitrary third-party scripts

Any script tag can be gated by a category without touching this library's code — mark it inert with type="text/plain" and tag it with the category that must be granted before it runs:

<script type="text/plain" data-consent-category="functional" src="https://chat.example.com/widget.js"></script>

Logging consent for an audit trail

By default, consent is only stored client-side (localStorage), which is enough for most sites. If your compliance requirements call for a server-side record (timestamp, which categories, policy version — useful if you ever need to demonstrate what a specific visitor consented to), wire config.onChange to send it wherever you need:

init({
  // ...categories, texts, etc.
  onChange(consent) {
    fetch('/api/consent-log', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ consent, ts: new Date().toISOString() })
    });
  }
});

onChange fires on every decision (accept all, reject, or save custom preferences), including the very first one. This library doesn't ship a backend for this on purpose — where that log lives (a database, a serverless function, a spreadsheet) is a decision for your app, not this package.

API

  • init(config) — mounts the banner (unless autoShow: false) and applies any previously stored consent.
  • has(categoryId) — whether a category is currently granted.
  • open() — opens the preferences panel (e.g. wire to a "Manage cookies" link).
  • reset() — clears stored consent (mostly for testing).

License

MIT