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

@unsass/selector

v1.5.0

Published

Sass functions and mixins to manage CSS selectors.

Downloads

452

Readme

Selector

Version Downloads License

Introduction

A small Sass toolkit for building CSS selectors programmatically. Compose scoped, prefixed or suffixed class names with pseudo-classes, pseudo-elements and @at-root support through concise, composable mixins and helpers, so selector logic stays readable and consistent.

Selector

Installing

npm install @unsass/selector

Usage

@use "@unsass/selector";

@include selector.create("foo", "md") {
    color: darkcyan;
}
.md\:foo {
    color: darkcyan;
}

Mixins

create($selector, $scope, $separator, $suffix, $pseudo-class, $pseudo-element, $root)

Builds a class selector from a name, with optional scope, separator, pseudo and @at-root options.

| Parameter | Description | Default | |-------------------|------------------------------------------------------------|---------| | $selector | Selector name (a leading . is stripped). | — | | $scope | Scope affix value, as a single token or a list of tokens. | null | | $separator | Scope affix separator. | ":" | | $suffix | Append the scope as a suffix instead of a prefix. | false | | $pseudo-class | Pseudo-class appended to the selector. | null | | $pseudo-element | Pseudo-element appended to the selector. | null | | $root | Wrap the output in an @at-root rule. | false |

@use "@unsass/selector";

@include selector.create("foo", "md") {
    color: darkcyan;
}
.md\:foo {
    color: darkcyan;
}

$scope

Pass a list to chain several scope tokens.

@use "@unsass/selector";

@include selector.create("foo", ("md", "lg")) {
    color: darkcyan;
}
.md\:lg\:foo {
    color: darkcyan;
}

$separator

Define your own scope separator character.

@use "@unsass/selector";

@include selector.create("foo", "md", "@") {
    color: darkcyan;
}
.md\@foo {
    color: darkcyan;
}

$suffix

Append the scope value as a suffix on the selector.

@use "@unsass/selector";

@include selector.create("foo", "md", $suffix: true) {
    color: darkcyan;
}
.foo\:md {
    color: darkcyan;
}

$pseudo-class

Define the pseudo-class suffix.

@use "@unsass/selector";

@include selector.create("foo", "hover", $pseudo-class: "hover") {
    color: darkcyan;
}
.hover\:foo:hover {
    color: darkcyan;
}

$pseudo-element

Define the pseudo-element suffix.

@use "@unsass/selector";

@include selector.create("foo", "before", $pseudo-element: "before") {
    color: darkcyan;
}
.before\:foo::before {
    color: darkcyan;
}

$root

Wrap the selector with an @at-root rule before code output.

@use "@unsass/selector";

.foo {
    .bar {
        @include selector.create(&, "md", $root: true) {
            color: darkcyan;
        }
    }
}
.md\:foo .bar {
    color: darkcyan;
}

media($query)

Wraps the content in a @media rule.

@use "@unsass/selector";

.foo {
    @include selector.media("screen") {
        color: darkcyan;
    }
}
@media screen {
    .foo {
        color: darkcyan;
    }
}

Functions

to-class($name)

Returns a class selector from a name.

@use "@unsass/selector";

$selector: selector.to-class("foo"); // ".foo"

to-id($name)

Returns an id selector from a name.

@use "@unsass/selector";

$selector: selector.to-id("foo"); // "#foo"

pseudo-class($selector, $pseudo-class)

Appends a pseudo-class to a selector.

@use "@unsass/selector";

$selector: selector.pseudo-class(".foo", "hover"); // ".foo:hover"

pseudo-element($selector, $pseudo-element)

Appends a pseudo-element to a selector.

@use "@unsass/selector";

$selector: selector.pseudo-element(".foo", "before"); // ".foo::before"

is($selector, $args…)

Restricts the selector with an :is() pseudo-class matching any of the given selectors.

@use "@unsass/selector";

$selector: selector.is("article", "h1", "h2"); // "article:is(h1, h2)"

where($selector, $args…)

Like is(), but with zero specificity through the :where() pseudo-class.

@use "@unsass/selector";

$selector: selector.where(".prose", "a", "button"); // ".prose:where(a, button)"

has($selector, $args…)

Restricts the selector to elements matching the relational :has() condition.

@use "@unsass/selector";

$selector: selector.has(".card", "> img"); // ".card:has(> img)"

exclude($selector, $args…)

Excludes the given selectors through a :not() pseudo-class. Named exclude because not is a reserved Sass keyword.

@use "@unsass/selector";

$selector: selector.exclude(".btn", ".btn--disabled"); // ".btn:not(.btn--disabled)"
$selector: selector.exclude(".item", ".a", ".b"); // ".item:not(.a, .b)"

These helpers return selectors, so they compose:

@use "@unsass/selector";

#{selector.exclude(selector.is(".x", "a", "b"), ".y")} {
    color: darkcyan;
}
.x:is(a, b):not(.y) {
    color: darkcyan;
}