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

@caprail-dev/consent

v0.1.4

Published

Region-aware, analytics-agnostic cookie-consent banner and state for React — Shadcn-styled, Tailwind-themeable.

Readme

@caprail-dev/consent

A region-aware cookie-consent banner and consent-state layer for React, made to pair with @caprail-dev/analytics — but analytics-agnostic, so it gates any tracker (GA, PostHog, your own).

  • Consent matrix as stateuseConsent() gives any component the live per-category grants and the actions to change them.
  • Tailwind, zero theme setup — styled with Tailwind's default palette (zinc), so it looks polished out of the box in any Tailwind project — no Shadcn tokens required. Override any color with className / classNames.
  • Region-aware — pass the visitor's country and it switches between opt-in (EEA/UK/CH/BR), opt-out (US-CA, with a "Do Not Sell/Share" link), and notice.
  • Mobile-first — bottom-anchored, stacked buttons that go inline on sm:, safe-area inset for notch devices, reduced-motion aware, focus-trapped dialog.
  • Extendable — register third-party services with a Loader that mounts only while its category is granted; nothing is bundled.

Install

bun add @caprail-dev/consent
# peers (you already have these in a React app)
bun add react react-dom

Setup (one required step)

Let Tailwind scan the package. The components are styled with Tailwind's default palette, so there are no tokens to define — but Tailwind v4 does not scan node_modules by default, so it won't emit those utility classes unless you point it at the package. Add this to the CSS file where you import Tailwind:

@import "tailwindcss";
@source "../node_modules/@caprail-dev/consent/dist";

(Adjust the relative path to your CSS file's location.)

Usage

import { ConsentProvider } from "@caprail-dev/consent";

export default function RootLayout({ children }) {
  return (
    <ConsentProvider /* country="DE" region="BY" */>{children}</ConsentProvider>
  );
}

The provider renders the banner and the consent-gated services itself — one tag.

Region detection

The package never fetches geo. Pass the visitor's country (and subdivision for US-CA) from your own edge — e.g. in a Next.js layout from the request headers:

import { headers } from "next/headers";

const h = await headers();
<ConsentProvider
  country={h.get("x-vercel-ip-country")}
  region={h.get("x-vercel-ip-country-region")}
>

With no country the mode is notice and the banner is informational.

Reading and reacting to consent

"use client";
import { useConsent } from "@caprail-dev/consent";

function Analytics() {
  const { consent } = useConsent();
  if (!consent.analytics) return null;
  return /* … load analytics … */;
}

Non-React listeners can use the caprail:consent window event, dispatched on every settled change:

window.addEventListener("caprail:consent", (e) => {
  const { analytics, marketing } = (e as CustomEvent).detail;
});

Gating third-party services

import Script from "next/script";
import { ConsentProvider, type ServiceDefinition } from "@caprail-dev/consent";

const services: ServiceDefinition[] = [
  {
    id: "ga",
    name: "Google Analytics",
    category: "analytics",
    Loader: ({ cookieless }) => (
      <Script src="https://www.googletagmanager.com/gtag/js?id=G-XXXX" />
    ),
  },
];

<ConsentProvider services={services}>{children}</ConsentProvider>;

A service's Loader mounts only while its category is granted and unmounts on revoke. cookieless (from the provider's cookieless prop) lets a loader run its SDK in a memory-only mode.

Custom categories

<ConsentProvider
  categories={[
    { id: "necessary", label: "Necessary", description: "Always on." },
    { id: "analytics", label: "Analytics", description: "Usage insights." },
    { id: "ads", label: "Advertising", description: "Personalized ads." },
  ]}
/>

necessary is always present and locked. ConsentState is keyed by your ids.

ConsentProvider props

| Prop | Type | Default | Notes | | ------------- | --------------------- | ----------------------------- | ----------------------------------------------- | | country | string \| null | null | ISO-3166-1 alpha-2, e.g. x-vercel-ip-country. | | region | string \| null | null | Subdivision, used for US-CA. | | categories | CategoryConfig[] | necessary/analytics/marketing | Toggles shown in "Manage". | | services | ServiceDefinition[] | [] | Trackers to gate + list. | | forceBanner | boolean | false | Show even with no non-essential category. | | cookieless | boolean | false | Forwarded to each Loader. | | cookieName | string | "caprail_consent" | First-party cookie name. | | onChange | (state) => void | — | Called after every settled change. |

useConsent()

Returns { consent, mode, region, categories, categoriesInUse, showBanner, acceptAll, rejectAll, setCategory, save, openBanner }. Call openBanner() from a footer "Cookie settings" link to let visitors revise a decision.

License

MIT