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

@consentlayer/sdk

v0.0.2

Published

JavaScript and React SDK for ConsentLayer — read consent state, gate code on user consent, and open the preferences modal. Pairs with the ConsentLayer banner.

Readme

@consentlayer/sdk

JavaScript and React SDK for ConsentLayer — read consent state, gate code on user consent, and open the preferences modal.

This SDK reads the consent cookie set by the ConsentLayer banner. You must have the banner script installed for it to work. See docs.consentlayer.com/docs/quickstart for banner setup.

Install

npm install @consentlayer/sdk
# or
pnpm add @consentlayer/sdk
# or
yarn add @consentlayer/sdk

Setting up the banner

The SDK is a no-op without the banner. Add this to your <head> (no defer, no async — it must run synchronously to block tracking scripts before they fire):

<script src="https://api.consentlayer.com/banner/YOUR_PROJECT_KEY/banner.js"></script>

Get your project key from app.consentlayer.com, or have an AI agent set it up via the ConsentLayer MCP server.

JavaScript API

import {
  hasConsent,
  getConsentState,
  onConsentChange,
  showPreferences,
  hasConsentCookie,
  getJurisdiction,
} from "@consentlayer/sdk";

hasConsent(category: string): boolean

Returns true if the user has consented to the given category.

if (hasConsent("statistics")) {
  loadAnalytics();
}

getConsentState(): ConsentState | null

Returns the full consent object, or null if the user hasn't interacted with the banner yet.

const state = getConsentState();
// {
//   version: 1,
//   timestamp: 1735689600000,
//   jurisdiction: "gdpr" | "ccpa" | "none",
//   gpcSignal: false,
//   doNotSell: false,
//   categories: { essential: true, statistics: true, marketing: false },
// }

onConsentChange(callback): () => void

Subscribe to consent updates. Returns an unsubscribe function.

const unsubscribe = onConsentChange((state) => {
  if (state.categories.marketing) {
    initFacebookPixel();
  }
});

showPreferences(): void

Programmatically open the preferences modal — useful for a footer "Cookie settings" link.

<button onClick={() => showPreferences()}>Cookie settings</button>

hasConsentCookie(): boolean

true if the user has made a consent choice (any choice — accepted, rejected, or customized). Useful for distinguishing "no decision yet" from "decided everything is off."

getJurisdiction(): "gdpr" | "ccpa" | "none"

Returns the jurisdiction the banner detected for this user.

React API

Import from the /react subpath:

import {
  ConsentLayerProvider,
  useConsent,
  useCategoryConsent,
  ConsentGate,
} from "@consentlayer/sdk/react";

Requires React 18 or later.

<ConsentLayerProvider>

Wrap your app once at the root.

import { ConsentLayerProvider } from "@consentlayer/sdk/react";

export default function App() {
  return (
    <ConsentLayerProvider>
      <YourApp />
    </ConsentLayerProvider>
  );
}

useConsent()

function AnalyticsLoader() {
  const { hasConsent, consentState, showPreferences } = useConsent();

  useEffect(() => {
    if (hasConsent("statistics")) loadGA();
  }, [hasConsent]);

  return <button onClick={showPreferences}>Cookie settings</button>;
}

useCategoryConsent(category)

Convenience hook that returns a boolean and re-renders when consent changes.

function MarketingPixel() {
  const allowed = useCategoryConsent("marketing");
  if (!allowed) return null;
  return <FacebookPixel />;
}

<ConsentGate>

Render children only if the user has consented to a category.

<ConsentGate category="marketing" fallback={<p>Enable marketing cookies to see this.</p>}>
  <YouTubeEmbed videoId="..." />
</ConsentGate>

TypeScript

Full types are bundled. Import the ConsentState type if you need it:

import type { ConsentState } from "@consentlayer/sdk";

Framework guides

For AI coding agents

To set up ConsentLayer end-to-end (create a project, scan the site, generate the install snippet), use the MCP server:

claude mcp add consentlayer --transport http "https://api.consentlayer.com/mcp"

See docs.consentlayer.com/docs/guides/ai-agents.

License

MIT