css-what

Node.js CI Coverage

A CSS selector parser.

Example

import * as CSSwhat from "css-what";

CSSwhat.parse("foo[bar]:baz")

~> [
    [
        { type: "tag", name: "foo" },
        {
            type: "attribute",
            name: "bar",
            action: "exists",
            value: "",
            ignoreCase: null
        },
        { type: "pseudo", name: "baz", data: null }
    ]
]

API

CSSwhat.parse(selector) - Parses selector.

The function returns a two-dimensional array. The first array represents selectors separated by commas (eg. sub1, sub2), the second contains the relevant tokens for that selector. Possible token types are:

name properties example output
tag name div { type: 'tag', name: 'div' }
universal - * { type: 'universal' }
pseudo name, data :name(data) { type: 'pseudo', name: 'name', data: 'data' }
pseudo name, data :name { type: 'pseudo', name: 'name', data: null }
pseudo-element name ::name { type: 'pseudo-element', name: 'name' }
attribute name, action, value, ignoreCase [attr] { type: 'attribute', name: 'attr', action: 'exists', value: '', ignoreCase: false }
attribute name, action, value, ignoreCase [attr=val] { type: 'attribute', name: 'attr', action: 'equals', value: 'val', ignoreCase: false }
attribute name, action, value, ignoreCase [attr^=val] { type: 'attribute', name: 'attr', action: 'start', value: 'val', ignoreCase: false }
attribute name, action, value, ignoreCase [attr$=val] { type: 'attribute', name: 'attr', action: 'end', value: 'val', ignoreCase: false }
child - > { type: 'child' }
parent - < { type: 'parent' }
sibling - ~ { type: 'sibling' }
adjacent - + { type: 'adjacent' }
descendant - { type: 'descendant' }
column-combinator - || { type: 'column-combinator' }

CSSwhat.stringify(selector) - Turns selector back into a string.


License: BSD-2-Clause

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

css-what - Installation

To install css-what via this registry, you'll need to install via the --registry parameter with your package manager.

n

NPM

npm install css-what --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Yarn

yarn config set registry https://js.registry.sudovanilla.org
yarn install css-what

Learn more about the config option.

PNPM

pnpm install css-what --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Bun Logo

Bun

bun install css-what --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Learn more about setting this up in your bunfig.toml configuration.


For Deno, add the following to your .npmrc file in your directory:

registry="https://js.registry.sudovanilla.org"

Then run the deno install command.

css-what - Download

Download Tarball (v8.0.0)

Integrity sha512-DH0Bqq3DNp5tdOReuNyAA+Ev4Y2GS5FMbZpeTLP6C4CDi0h5nL0BmUPChXw3o/qbHLDWHl49sbNqQVY7bMSDdw==
SHASUM 237889d60c4afef4736892f39e133ab4c8c21f0c
Tarball https://js.registry.sudovanilla.org/css-what/-/css-what-8.0.0.tgz