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-media-query-match-kit

v0.1.0

Published

Parse and match CSS media queries with structured diagnostics.

Readme

css-media-query-match-kit

License: MPL-2.0 CI

Parse and match small CSS media query lists with structured diagnostics.

css-media-query-match-kit is a clean-room TypeScript utility for tools that need to preview or test responsive rules without calling window.matchMedia. The core is framework-agnostic, browser-friendly, ESM-only, and has no runtime dependencies.

Demo

Try the interactive demo: https://packages.wasta-wocket.fr/css-media-query-match-kit/

Install

npm install css-media-query-match-kit

Quick Start

import { matchMediaQueryList } from "css-media-query-match-kit";

const result = matchMediaQueryList(
  "screen and (min-width: 768px) and (orientation: landscape)",
  { type: "screen", width: 1280, height: 720 }
);

console.log(result.matches); // true

Invalid input returns diagnostics instead of throwing:

import { parseMediaQueryList } from "css-media-query-match-kit";

const result = parseMediaQueryList("screen and (min-width: 48em)");

console.log(result.ok); // false
console.log(result.diagnostics[0]?.code); // "invalid-length"

Supported Scope

This package intentionally targets a small, inspectable subset:

  • media types: all, screen, print, speech;
  • query lists separated by commas;
  • not and only modifiers;
  • and-joined feature conditions;
  • min- and max- comparisons;
  • features: width, height, orientation, aspect-ratio, resolution, hover, pointer, color, monochrome;
  • units: px, dppx, dpi, and integer ratios such as 16/9.

It does not try to replace a full CSS parser. Modern range syntax such as (width >= 768px), relative units such as em or rem, nested boolean groups, and preference features such as prefers-color-scheme are intentionally outside this first stable scope. Unsupported features are reported as diagnostics so caller UIs can explain what was skipped.

API

parseMediaQueryList(input, options?)

Parses a media query list and returns { ok, input, queries, diagnostics }.

const parsed = parseMediaQueryList("screen and (max-width: 600px), print");

Options:

  • maxInputLength: reject unexpectedly large input before parsing. Default: 100_000.

matchMediaQueryList(input, environment, options?)

Parses and evaluates the list against an explicit environment object.

const result = matchMediaQueryList("(hover: hover) and (pointer: fine)", {
  type: "screen",
  hover: "hover",
  pointer: "fine"
});

formatMediaQueryList(queries)

Formats parsed queries back to normalized CSS.

const parsed = parseMediaQueryList("screen and (min-width: 768px)");

if (parsed.ok) {
  console.log(formatMediaQueryList(parsed.queries));
}

Environment

type MediaQueryEnvironment = {
  type?: "all" | "screen" | "print" | "speech";
  width?: number;
  height?: number;
  resolution?: number; // dppx
  hover?: "none" | "hover";
  pointer?: "none" | "coarse" | "fine";
  color?: number;
  monochrome?: number;
};

width and height are CSS pixels. resolution is stored in dppx; 96dpi is normalized to 1.

Diagnostics

Diagnostic codes are stable strings intended for tests, logs, and UI hints:

  • expected-string
  • expected-environment
  • invalid-options
  • empty-input
  • input-too-long
  • empty-query
  • unsupported-condition
  • unsupported-media-type
  • unsupported-feature
  • missing-feature-value
  • invalid-feature-syntax
  • invalid-length
  • invalid-resolution
  • invalid-ratio
  • invalid-number

Browser Compatibility

The core does not perform I/O, does not read global browser state, and does not depend on Node-only APIs such as fs, path, Buffer, or process.

Package quality

  • TypeScript source with generated declarations.
  • ESM-only package with no runtime dependencies.
  • Defensive parsing API: invalid input returns diagnostics instead of throwing.
  • CI runs npm ci, typecheck, build, and test.
  • Tested on Node.js 20 and 22 with GitHub Actions.

License

MPL-2.0