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

caligula

v0.4.0

Published

Zero-dependency CSS filter: remove rules and declarations and rewrite selectors with PostCSS-identical output, 6-13x faster than PostCSS.

Readme

caligula

Zero-dependency CSS filter. PostCSS-identical output, 6–13× faster.

Remove rules, at-rules and declarations, or rewrite selectors, with PostCSS-style visitors. caligula edits the source text instead of building an AST, so its output is byte-identical to the same visitors run as a PostCSS plugin (with postcss-discard-empty), at a fraction of the cost.

bun i caligula
import { filterCss } from "caligula";

const { css, map, removed, skipped } = filterCss(source, {
  rule: ({ selector }) => used.has(selector) || false, // false = remove
  atRule: (atRule) =>
    atRule.name !== "keyframes" || usedKeyframes.has(atRule.params) || false,
  map: { source: "app.css" },
});

API

filterCss(css, options?) => { css, skipped, removed, map? }

| Option | Description | |:---|:---| | rule({ selector, parsed }) | Return false to remove the rule, a string to replace its selector, or anything else to keep it. parsed is the selector list parsed by parseSelectorList (below), computed the first time it's read. | | atRule({ name, params, walkDecls }) | Return false to remove the at-rule. | | decl({ prop, value }) | Return false to remove the declaration. Called for every declaration in a kept rule or at-rule, after the visitor of the rule or at-rule that holds it. | | readDecls | At-rule names (case-insensitive) whose declarations atRule reads through walkDecls(cb(prop, value)), e.g. ["font-face"]. | | discardEmpty | Drop containers left with no children, like postcss-discard-empty. Default true. | | map | true or { source, includeContent } returns a v3 source map. |

selector, params and declaration values read exactly as PostCSS's rule.selector, atRule.params and decl.value would: comments dropped per PostCSS's raw() rule, !important stripped. Visitors run in PostCSS's order, and a rule whose selector was rewritten, or that lost a declaration, is visited again, as PostCSS's Rule visitor would be. Each declaration is visited once.

To list selectors without changing anything, return nothing from rule and check skipped.

To drop custom properties nothing reads, run it twice: once to prune rules, then again with decl over the result.

const { css: pruned } = filterCss(source, { rule });
const read = new Set(pruned.match(/(?<=var\(\s*)--[\w-]+/g));
const { css } = filterCss(pruned, {
  decl: ({ prop }) => !prop.startsWith("--") || read.has(prop),
});

caligula/selector

Selector utilities for deciding what to keep, without a CSS parser of your own.

import {
  parseSelector,
  parseSelectorList,
  requiredClasses,
  splitSelectorList,
} from "caligula/selector";

splitSelectorList(".a, .b:is(.c, .d)"); // [".a", ".b:is(.c, .d)"]

const parsed = parseSelector(".x .y > .z:not(.w)");
parsed.compounds; // [{ classes: ["x"], negated: [] }, { classes: ["y"], negated: [] }, { classes: ["z"], negated: ["w"] }]
parsed.combinators; // [" ", ">"]
parsed.subject; // the last compound, { classes: ["z"], negated: ["w"] }

requiredClasses(".bx--a .x > .bx--b", { prefix: "bx--" }); // ["bx--a", "bx--b"]

| Function | Returns | |:---|:---| | splitSelectorList(list) | The selectors in a list, trimmed: split on commas outside parentheses, attribute selectors, strings and comments. | | parseSelector(selector) | { text, compounds, combinators, subject } for one selector. Throws on a list. | | parseSelectorList(list) | parseSelector for each selector in a list, in one pass. | | requiredClasses(selector, { prefix? }) | Every class the selector requires, across its compounds, deduplicated; prefix keeps only those that start with it. |

A compound's classes are what an element must have to match: its own .a, plus the classes every branch of an :is()/:where() (and :matches(), :-webkit-any(), :-moz-any()) requires. Classes in :has() are on other elements and aren't listed; those in :not() are listed in negated. Names are unescaped (.sm\:p-4 is sm:p-4). A leading combinator (> .a in nested CSS) gets an empty compound before it. Malformed selectors parse as far as they make sense; nothing but parseSelector on a list throws.

Features

  • PostCSS parity. For every input it doesn't skip, the output equals postcss([visitors, discardEmpty()]).process(css).css, and visitors see the same strings in the same order. It's tested on Bootstrap, Carbon, Tailwind v4-style output and modern syntax (nesting, @layer, @container, @scope, @property), and by a differential fuzzer that also compares visitor calls and declaration values.
  • 6–13× faster than PostCSS. No value parsing and no re-printing: kept text is copied from the source.
  • Source maps. Optional v3 maps for the output.
  • No-op is the identity. With no visitor changes, the output is the input, byte for byte.
  • Fail-safe. A syntax error, nesting deeper than 1,000 blocks, or anything else it can't reproduce exactly returns the input unchanged with skipped: true, before any visitor runs.
  • Small and portable. No dependencies, no Node APIs, ~7 kB gzipped.
  • Deliberate differences from PostCSS:
    • < is never escaped.
    • A reversed BOM (U+FFFE) is left as-is; PostCSS rewrites it to U+FEFF.
    • postcss-discard-empty's extra deletions (empty declarations, rules with an empty selector in the source, paramless @foo;) aren't reproduced. A rule a visitor rewrites to "" is dropped, as PostCSS does.

Benchmarks

Apple M2, medians of warm calls. The filter job drops every rule whose selector names none of a few kept classes.

| Stylesheet | Job | caligula | PostCSS | Lightning CSS[^lightning] | |:---|:---|:---|:---|:---| | Carbon white.css, 562 kB min | filter | 2.9 ms | 18.5 ms (6.3×) | 28.7 ms (9.8×) | | | filter + source map | 3.4 ms | 20.6 ms (6.1×) | – | | | round trip | 2.4 ms | 16.0 ms (6.8×) | 10.0 ms (4.2×) | | bootstrap.css, 280 kB formatted | filter | 1.4 ms | 17.7 ms (13×) | 13.0 ms (9.6×) | | | filter + source map | 1.8 ms | 11.6 ms (6.5×) | – | | | round trip | 1.2 ms | 11.8 ms (9.9×) | 4.5 ms (3.8×) | | bootstrap.min.css, 232 kB | filter | 1.0 ms | 9.5 ms (9.3×) | 13.0 ms (13×) | | | filter + source map | 1.4 ms | 8.2 ms (6.1×) | – | | | round trip | 0.96 ms | 7.8 ms (8.2×) | 4.6 ms (4.7×) | | Tailwind v4-shaped utilities, 145 kB | filter | 0.77 ms | 5.8 ms (7.6×) | 13.9 ms (18×) | | | round trip | 0.82 ms | 6.3 ms (7.7×) | 4.3 ms (5.2×) |

The first call in a fresh process runs about 2–3× slower while the JIT warms up (Carbon: 9.5 ms). Peak memory is about 3–7× the input size.

[^lightning]: Lightning CSS does a different job: it re-prints the stylesheet (so it doesn't preserve the source) and can do much more (minify, lower syntax, bundle). Its filter runs a JS visitor; its round trip is native only.

Limitations

  • Filter only. It can remove rules, at-rules and declarations, and rewrite selectors. It can't edit declarations or insert nodes.
  • No input source map chaining. It maps to the CSS it was given, not through a previous map.
  • Declaration values are only read under readDecls at-rules, or everywhere when decl is set. That keeps the fail-safe check ahead of the visitors, and costs nothing when no visitor needs them.