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

@projectwallace/css-code-coverage

v0.9.0

Published

Generate useful CSS Code Coverage report from browser-reported coverage

Readme

CSS Code Coverage

[!WARNING] This is a very experimental approach to calculating CSS Code Coverage and currently very much a work in progress.

Takes your generated coverage files and turns them into something actually usable. Accepts coverage reports generated by browsers (Edge/Chrome/chromium), Puppeteer, Playwright.

Features include:

  • 🤩 Prettifies CSS for easy inspection and updates coverage ranges after prettification
  • 🪄 Marks each line of each CSS file as covered or uncovered
  • 📑 A single stylesheet that's reported over multiple URL's is combined into a single one, coverage ranges merged
  • 🗂️ Creates a report of total line coverage, byte coverage and coverage details per individual stylesheet discovered

Installation

npm install @projectwallace/css-code-coverage

Usage

import { calculate_coverage } from '@projectwallace/css-code-coverage'

let report = await calculcate_coverage(coverage_data)

// => report.line_coverage_ratio: 0.80
// => report.byte_coverage_ratio: 0.85
// => report.total_lines: 1000
// => report.covered_lines: 800
// etc.

See src/index.ts for the data that's returned.

Collecting CSS Coverage

There are two principal ways of collecting CSS Coverage data:

Coverage API (preferred)

Both Puppeteer and Playwright provide an API to programmatically get the coverage data, allowing you to put that directly into this library. Here is the gist:

// Start collecting coverage
await page.coverage.startCSSCoverage()
// Load the page, do all sorts of interactions to increase coverage, etc.
await page.goto('http://example.com')
// Stop the coverage and store the result in a variable to pass along
let coverage = await page.coverage.stopCSSCoverage()

// Now we can process it
import { calculate_coverage } from '@projectwallace/css-code-coverage'

let report = calculcate_coverage(coverage)

Browser devtools

In Edge, Chrome or chromium you can manually collect coverage in the browser's DevTools. In all cases you'll generate coverage data manually and the browser will let you export the data to a JSON file. Note that this JSON contains both JS coverage as well as the CSS coverage. Learn how it works:

  • Collect coverage in Microsoft Edge: https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/coverage/
  • Collect coverage in Google Chrome: https://developer.chrome.com/docs/devtools/coverage/

Additionally, DevTools Tips writes about it in their explainer.

You end up with one or more JSON files that contain coverage data. We provide a helper parse_coverage() that both parses the JSON and validates it so you can pass it directly into calculate_coverage().

// Read a single JSON or a folder full of JSON files with coverage data
// Coverage data looks like this:
// {
//   url: 'https://www.projectwallace.com/style.css',
//   text: 'a { color: blue; text-decoration: underline; }', etc.
//   ranges: [
//     { start: 0, end: 46 }
//   ]
// }
import { parse_coverage } from '@projectwallace/css-code-coverage'

let files = await fs.glob('./css-coverage/**/*.json')
let coverage_data = []

for (let file of files) {
	let json_content = await fs.readFile(file, 'urf-8')
	coverage_data.push(...parse_coverage(json_content))
}

CLI

Use the CLI tool (css-coverage) to check if coverage meets minimum requirements, globally and/or per file.

css-coverage --coverage-dir=<dir> --min-coverage=<number> [options]

CLI docs