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

@fullhuman/purgecss-from-tsx

v8.0.0

Published

TSX extractor for PurgeCSS

Readme

@fullhuman/purgecss-from-tsx

npm version

TSX extractor for PurgeCSS. This extractor parses TSX files (TypeScript + JSX) and extracts used selectors from component names, className, and id attributes.

Installation

npm install @fullhuman/purgecss-from-tsx --save-dev

Usage

With PurgeCSS

import PurgeCSS from "purgecss";
import purgeFromTsx from "@fullhuman/purgecss-from-tsx";

const result = await new PurgeCSS().purge({
  content: ["**/*.tsx"],
  css: ["**/*.css"],
  extractors: [
    {
      extractor: purgeFromTsx(),
      extensions: ["tsx"],
    },
  ],
});

With Custom Options

You can pass custom options for both the TypeScript compiler and the acorn parser:

import purgeFromTsx from "@fullhuman/purgecss-from-tsx";

const extractor = purgeFromTsx({
  // Acorn parser options
  acornOptions: {
    ecmaVersion: 2020,
    sourceType: "module",
  },
  // TypeScript compiler options
  tsOptions: {
    target: ts.ScriptTarget.ES2020,
  },
});

Standalone

You can use the extractor standalone to extract selectors from TSX content:

import purgeFromTsx from "@fullhuman/purgecss-from-tsx";

const tsx = `
  interface Props {
    title: string;
  }
  
  function Card({ title }: Props): JSX.Element {
    return (
      <div className="card">
        <h2 id="card-title" className="card-title">{title}</h2>
        <Button className="btn btn-primary" />
      </div>
    );
  }
`;

const selectors = purgeFromTsx()(tsx);

console.log(selectors);
// ["div", "card", "h2", "card-title", "card-title", "Button", "btn", "btn-primary"]

API

purgeFromTsx(options?: Options): (content: string) => string[]

Creates an extractor function for TSX content.

Parameters

Returns

A function that takes TSX content as a string and returns an array of selectors.

How It Works

This extractor works in two steps:

  1. TypeScript Transpilation - Uses the TypeScript compiler to transpile TSX to JSX, stripping type annotations while preserving JSX syntax
  2. JSX Extraction - Uses @fullhuman/purgecss-from-jsx to extract selectors from the resulting JSX

What It Extracts

The extractor parses TSX and extracts:

  1. Component names - JSX element names (e.g., div, Header, MyComponent)
  2. className values - String values from className attributes, split by spaces
  3. id values - String values from id attributes

Example

interface CardProps {
  variant: "primary" | "secondary";
}

const Card: React.FC<CardProps> = ({ variant }) => (
  <article className="card card-hover" id="featured">
    <CardHeader className="p-4" />
    <CardBody />
  </article>
);

Extracted selectors: ["article", "card", "card-hover", "featured", "CardHeader", "p-4", "CardBody"]

Limitations

  • Only extracts static string values from className and id
  • Dynamic expressions like className={styles.container} or template literals are not fully supported
  • For dynamic class names, consider using PurgeCSS's safelist option

License

MIT License