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

@opencookies/scanner

v0.0.2

Published

Static cookie and vendor detection for OpenCookies. Scans your source for known third-party scripts and the cookies they (or your code) set.

Downloads

240

Readme

@opencookies/scanner

Static cookie and vendor detection for OpenCookies. Scans your source for known third-party scripts and the cookies they (or your code) set.

The scanner is a pure library. The Vite plugin (@opencookies/vite) and the audit CLI (@opencookies/cli) are built on top of it.

Install

bun add -D @opencookies/scanner

Usage

import { scan } from "@opencookies/scanner";

const result = await scan({ cwd: process.cwd() });
console.log(result.cookies); // Cookie[]
console.log(result.vendors); // VendorHit[]
console.log(result.ungated); // Ungated[]

ScanOptions:

| field | default | notes | | ------------- | -------------------------------------------------------------------- | ---------------------------------- | | cwd | required | the project root | | include | **/*.{js,jsx,ts,tsx,vue,svelte,mjs,cjs,mts,cts} | tinyglobby patterns | | exclude | node_modules, dist, .next, .svelte-kit, coverage, *.d.ts | tinyglobby patterns | | rules | every built-in rule | override to run a subset | | vendors | bundled registry | override or extend the vendor list | | concurrency | os.availableParallelism() | per-file workers |

What it detects

| Rule | Pattern | | ------------------- | -------------------------------------------------------------------------- | | document-cookie | document.cookie = "..." | | js-cookie | Cookies.set/... from js-cookie | | cookies-next | setCookie(...) from cookies-next or nookies | | react-cookie | the setter from useCookies() | | next-headers | cookies().set(...) from next/headers | | set-cookie-header | Set-Cookie in a Response / Headers / NextResponse | | vendor-imports | imports, dynamic imports, and global calls for the bundled vendor registry |

The bundled vendor registry covers Google Analytics / Tag Manager, Meta Pixel, PostHog, Segment, Mixpanel, Hotjar, Intercom, LinkedIn Insight, Twitter/X Pixel, TikTok Pixel, Reddit Pixel, Sentry, and Datadog. Pass vendors: to extend or replace it.

Suppression comments

// opencookies-ignore-next-line
document.cookie = "experiment=on";
// opencookies-ignore-file
// — placed in the first 10 lines, suppresses all hits in this file.

The "ungated" heuristic

A hit is reported as ungated when the scanner cannot find evidence that it runs only after the user has consented. The heuristic is intentionally conservative — it favours false negatives over false positives.

A hit is treated as gated when any ancestor in its AST path is one of:

  • a JSX element named <ConsentGate>
  • an if / ternary whose test contains a .has(...) call (matches both consent.has("analytics") and cookies.has("session"))
  • a function named acceptAll, acceptNecessary, or any name beginning with set (catches the common setSessionCookie / setLocaleCookie shape)

This is not a control-flow analysis. Treat the ungated array as a "please double-check" list, not a definitive enforcement signal — the runtime is what enforces consent. See OpenCookies core for the runtime story.

Custom rules

import { defineRule, scan, defaultRules } from "@opencookies/scanner";

const banPlausible = defineRule({
  name: "plausible-import",
  visit: (ctx) => {
    if (ctx.node.type !== "ImportDeclaration") return;
    const src = (ctx.node as { source?: { value?: string } }).source?.value;
    if (src === "plausible-tracker") {
      const { line, column } = ctx.position(ctx.node.start);
      ctx.report({
        file: ctx.file,
        line,
        column,
        vendor: "plausible",
        category: "analytics",
        via: "import",
      });
    }
  },
});

await scan({ cwd: process.cwd(), rules: [...defaultRules, banPlausible] });

Vendor registry contributions

The bundled list lives in src/vendors.json. Each entry has the shape:

{
  "vendor": "stripe",
  "category": "payments",
  "imports": ["@stripe/stripe-js", "stripe"],
  "globals": ["Stripe"],
  "scriptUrls": ["https://js.stripe.com/v3/"]
}

PRs that add or correct entries are welcome. Please include a one-liner about the categorisation in your commit message; the categories are deliberately informal and align loosely with the GDPR/CCPA buckets the runtime uses.

Tests

bun test (or vp test) runs:

  • per-rule fixtures under __fixtures__/rules/<rule>/
  • integrated synthetic projects under __fixtures__/projects/
  • hand-authored real-world snippets under __fixtures__/real-world/
  • a 1000-file synthetic perf assertion (must complete in under 2s)

OPENCOOKIES_REAL_WORLD=1 vp test additionally downloads pinned tarballs of Cal.com and Documenso into tests/real-world/.cache/ (gitignored) and runs the scanner against them, asserting zero false positives on a curated allowlist of known-clean files. The cache is reused across runs.

See also

  • @opencookies/vite — Vite plugin that runs the scanner during dev and CI (recommended; you usually don't call the scanner directly)
  • @opencookies/cli — terminal entry point for one-off scans and config sync
  • @opencookies/core — runtime that actually enforces the consent decisions the scanner is checking for

License

Apache-2.0