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

@darmiuskz/cookie-consent-manager

v1.0.1

Published

A lightweight, backend-ready cookie consent logic manager.

Readme

🍪 cookie-consent-kit

A flexible, customizable, framework-friendly cookie consent manager.
Supports both React and Vanilla JS usage.
Works with modals, banners, and page-based preference management.


✨ Features

  • ✅ Drop-in <Banner /> and <Modal /> components for React
  • ✅ Plain showBanner() + modal for HTML/JS
  • ✅ Support for custom categories (analytics, marketing, etc.)
  • ✅ Backend syncing with token & API endpoint
  • ✅ Automatically enables analytics (e.g. GA4) if consented
  • ✅ One-time setup with full reusability across projects

🚀 Installation

NPM

npm install @darmiuskz/cookie-consent-manager

⚙️ setupCookieConsent(options)

Options

| Option | Type | Description | |-------------|----------|-----------------------------------------------------------------------------| | serverMode| boolean| Enable syncing with backend. If true, fetches and stores consent via API. | | apiUrl | string | URL of your consent API (used when serverMode: true). | | userToken | string | Token to identify the current user (e.g. JWT or session ID). | | categories| object | List of cookie categories the user can consent to (see below). |

🍪 Category Object

analytics: {
  label: 'Analytics',                    // Display name for the category
  description: 'Track user behavior',    // Optional longer explanation
  customizable: true,                    // Whether user can toggle it
  scripts: [                             // Optional scripts to inject
    {
      src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX',
      name: 'Google Tag Manager'
    }
  ]
}

Banner Options

  • message — Text to show at the top of the banner
  • buttons.customize — Text for the customize button
  • buttons.showCustomize — Boolean to show/hide the customize button
  • customizeMode'modal' or 'page'; defines what happens when user clicks Customize. By default, it is 'modal'
  • customizePageUrl — URL to redirect to if customizeMode: 'page'

🔧 Setup (React or JS)

React (TypeScript)

import { setupCookieConsent, Banner, Modal } from '@darmiuskz/cookie-consent-kit/react';

setupCookieConsent({
  serverMode: true,
  apiUrl: 'https://your-api.com/consent',
  userToken: 'abc123',
  categories: {
    label: 'Analytics',
      description: 'Helps us understand user behavior.',
      customizable: true,
      scripts: [
        {
          src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX',
          name: 'Google Tag Manager'
        }
      ],
    },
    marketing: {
      label: 'Marketing',
      description: 'Tracks ads and conversions.',
      customizable: true,
      scripts: [
        {
          inline: `
            !function(f,b,e,v,n,t,s)
            {if(f.fbq)return;n=f.fbq=function(){n.callMethod ?
            n.callMethod.apply(n,arguments):n.queue.push(arguments)};
            if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
            n.queue=[];t=b.createElement(e);t.async=!0;
            t.src=v;s=b.getElementsByTagName(e)[0];
            s.parentNode.insertBefore(t,s)}(window, document,'script',
            'https://connect.facebook.net/en_US/fbevents.js');
            fbq('init', 'YOUR_PIXEL_ID'); 
            fbq('track', 'PageView');
          `,
          name: 'Facebook Pixel'
        }
      ]
    }
  }
});

Then in your layout

<Banner
  message="We use cookies 🍪 to improve your experience."
  buttons={{ customize: "Customize" }}
  customizeMode="modal"
/>

<Modal>
  <YourPreferenceComponent /> {/* use useConsentCategories() hook here */}
</Modal>

Vanilla JS / HTML

<script>
  import { setupCookieConsent, showBanner } from '@darmiuskz/cookie-consent-manager';
  window.CookieConsent.setupCookieConsent({
    serverMode: false,
    categories: {
      analytics: {
        label: 'Analytics',
        description: 'Tracks how users interact with the site',
        customizable: true,
        scripts: [
          {
            src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX',
            name: 'Google Tag Manager'
          },
        ]
      }
    }
  });

  window.CookieConsent.showBanner({
    message: "We use cookies 🍪",
    buttons: {
      customize: "Customize"
    },
    customizeMode: "page",
    customizePageUrl: "/cookie-settings"
  });
</script>

🛠️ Custom Modals in Native JS

<script>
import { injectCustomModal, getConsentHelpers, getConsentCategories } from 'cookie-consent-manager';
  const categories = getConsentCategories();

  const html = `
    <div class="my-cookie-modal">
      <h2>Cookie Preferences</h2>
      ${categories.map(cat => `
        <label>
          <input type="checkbox" name="${cat.key}" ${cat.checked ? 'checked' : ''} />
          ${cat.label}
        </label>
      `).join('')}
      <button onclick="saveMyConsent()">Save</button>
      <button onclick="window.CookieConsent.getConsentHelpers().rejectAll()">Reject All</button>
    </div>
  `;

  function saveMyConsent() {
    const selected = Array.from(document.querySelectorAll('input[type=checkbox]:checked')).map(i => i.name);
    getConsentHelpers().save(selected);
    document.querySelector('.my-cookie-modal')?.remove();
  }

  injectCustomModal(html);
</script>