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

css-module-dts

v0.1.4

Published

Generate .d.ts files for CSS modules

Readme

css-module-dts

Generate TypeScript declaration (.d.ts) files for CSS Modules.

This small CLI and library scans a directory for CSS/SCSS/LESS module files (by default **/*.module.{css,sass,scss,less}), extracts class names, and generates .d.ts style declaration output that can be written to a file or printed to stdout.

Key features

  • Works with CSS, SCSS, and LESS (uses PostCSS + language parsers)
  • CLI-friendly: print results or write to a file
  • Small, dependency-light implementation

Installation

Install from npm:

npm install --save-dev css-module-dts

Or use npx for a one-off run (when published):

npx css-module-dts <rootDir>

Local development

  1. Install dev deps:
npm install
  1. Build the project:
npm run build
  1. Run the CLI from the built output:
node dist/cli.js <rootDir> -p "**/*.module.{css,sass,scss,less}" -w out.d.ts

Usage (CLI)

css-module-dts [options] <rootDir>

Positional arguments

  • rootDir Root directory to scan for CSS modules (required)

Options

  • -p, --pattern Glob pattern to locate module files (default: **/*.module.{css,sass,scss,less})
  • -w, --write Path to write the generated declaration output. If omitted, output is written to stdout.

Examples

Print declarations for all module files under src

npx css-module-dts src

Write declarations to types.d.ts (local, after building)

npx css-module-dts src -w types.d.ts

Library API

The package also exposes small programmatic helpers (ESM):

  • extractCssModules(rootDir: string, globPattern: string): Promise<string>

    • Scans files matching the glob within rootDir, extracts class names, and returns the combined .d.ts content as a single string.
  • extractClassNames(css: string): Set

    • Extracts class names from a CSS/SCSS/LESS string and returns a Set of names.
  • createDtsFile(moduleName: string, classNames: Set): string

    • Creates the .d.ts declaration string for a single module path and its class names.

You can import and use these from the built files (dist) or the source during development (Node must support ESM):

import extractCssModules from './dist/extract-css-modules.js'; // or during dev after build: // import extractCssModules from './src/extract-css-modules.js';

CI / Release (GitHub Actions)

This repository includes GitHub Actions workflows to run CI and publish releases:

  • .github/workflows/ci.yml — runs on push and pull requests to main. It installs dependencies, runs npm run check, runs tests, and builds the project.
  • .github/workflows/release.yml — runs on push to main and uses Changesets to create releases and publish to npm. It expects NPM_TOKEN and uses the default GITHUB_TOKEN provided by Actions.
  • .github/workflows/publish-manual.yml — a manual workflow_dispatch workflow that builds and publishes the package. It accepts an optional tag input for dist tags.

Required repository secrets

  • NPM_TOKEN — an npm automation token with publish access. Add this in the repository Settings → Secrets and variables → Actions.
  • GITHUB_TOKEN — automatically provided to workflows; no action needed.

Manual publish

To manually publish the package from the Actions UI, go to the Actions tab, select Manual publish, click Run workflow, and optionally set a tag (like next).

Notes

  • The release workflow uses Changesets. Ensure you create Changesets (e.g., npx changeset) when you want to release new versions.
  • The workflows assume npm publish --access public. If you need a different registry or publish command, update the workflow files accordingly.

Tests

Run the test suite with:

npm test

Contributing

Contributions welcome — please open issues or PRs. A few suggestions:

  • Run formatting/lint checks before committing: npm run fix / npm run check
  • Add tests for parsing edge-cases when adding features

License

MIT — see the license field in package.json.

Notes and assumptions

  • This project uses ESM ("type": "module") and expects a relatively recent Node.js that supports ESM imports (Node 14+ recommended).
  • The CLI specified in package.json points to dist/cli.js; make sure to run npm run build before using the local CLI.