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

@siteimprove/alfa-selector

v0.112.0

Published

Functionality for working with CSS selectors and individual selector matching

Downloads

4,214

Readme

Alfa Selector

Model and parse CSS selectors.

Circularity problems

The main problem with CSS selectors is that they are somewhat circularly defined, mostly due to functional pseudo-classes. That is, even a simple selector can be a functional pseudo-class which can contain a list of complex selectors (e.g. :is(div span, a:focus)).

In order to avoid creating circular dependencies, we have some specific tricks not used elsewhere in Alfa:

Several subdirectories have a file of the same name defining the commonalities (classes, …), and an index re-exporting everything. For example, selector/pseudo/pseudo-element/pseudo-element.ts defines the common abstract classes used, after.ts, cue.ts, … define the specific concrete classes for each of these selectors, and index.ts groups everything (e.g., building the global pseudo-element parser) and re-exports for outside use.

Thus, when importing within this package, it is often better to import from the specific files instead of the index, to avoid circular dependencies. For example nth-child.ts imports Universal from simple/universal.ts instead of from simple/index.ts, because the latter (indirectly) imports from nth-child.ts (through pseudo-class/index.ts). Even if the circularity is OK in that case, it is better to avoid it altogether.

Similarly, the type guards (isSimple, …) defined as functions in their associated namespace as we usually do in Alfa cannot be used inside this package. Here also, host.parser needs to check that the argument is compound (not complex), but since a :host pseudo-class is also a compound selector, we'd create a circular dependency. Instead, inside this package, we check the type property. That is, in this package use type === "…" (or the BaseSelector.hasFooType helpers) to avoid circular dependencies, but outside of this package use Simple.isSimple as usual.

The parsers are facing the same circularity problems. While it would be possible to define all parsers in a single file as mutually recursive functions, this would both be impractically big, and have poor locality. Instead, most parsers take a parser continuation (with extra options) as a parameter, use it where needed, and forward it to sub-parsers.