• Version 6.1.0
  • Published
  • 66 kB
  • No dependencies
  • BSD-2-Clause license


npm i css-what
yarn add css-what
pnpm add css-what


a CSS selector parser



variable IgnoreCaseMode

const IgnoreCaseMode: {
readonly Unknown: null;
readonly QuirksMode: 'quirks';
readonly IgnoreCase: true;
readonly CaseSensitive: false;
  • Modes for ignore case.

    This could be updated to an enum, and the object is the current stand-in that will allow code to be updated without big changes.


function isTraversal

isTraversal: (selector: Selector) => selector is Traversal;
  • Checks whether a specific selector is a traversal. This is useful eg. in swapping the order of elements that are not traversals.

    Parameter selector

    Selector to check.

function parse

parse: (selector: string) => Selector[][];
  • Parses selector, optionally with the passed options.

    Parameter selector

    Selector to parse.

    Parameter options

    Options for parsing.


    Returns a two-dimensional array. The first dimension represents selectors separated by commas (eg. sub1, sub2), the second contains the relevant tokens for that selector.

function stringify

stringify: (selector: Selector[][]) => string;
  • Turns selector back into a string.

    Parameter selector

    Selector to stringify.


interface AttributeSelector

interface AttributeSelector {}

    property action

    action: AttributeAction;

      property ignoreCase

      ignoreCase: 'quirks' | boolean | null;

        property name

        name: string;

          property namespace

          namespace: string | null;

            property type

            type: SelectorType.Attribute;

              property value

              value: string;

                interface PseudoElement

                interface PseudoElement {}

                  property data

                  data: string | null;

                    property name

                    name: string;

                      property type

                      type: SelectorType.PseudoElement;

                        interface PseudoSelector

                        interface PseudoSelector {}

                          property data

                          data: DataType;

                            property name

                            name: string;

                              property type

                              type: SelectorType.Pseudo;

                                interface TagSelector

                                interface TagSelector {}

                                  property name

                                  name: string;

                                    property namespace

                                    namespace: string | null;

                                      property type

                                      type: SelectorType.Tag;

                                        interface Traversal

                                        interface Traversal {}

                                          property type

                                          type: TraversalType;

                                            interface UniversalSelector

                                            interface UniversalSelector {}

                                              property namespace

                                              namespace: string | null;

                                                property type

                                                type: SelectorType.Universal;


                                                  enum AttributeAction

                                                  enum AttributeAction {
                                                  Any = 'any',
                                                  Element = 'element',
                                                  End = 'end',
                                                  Equals = 'equals',
                                                  Exists = 'exists',
                                                  Hyphen = 'hyphen',
                                                  Not = 'not',
                                                  Start = 'start',

                                                    member Any

                                                    Any = 'any'

                                                      member Element

                                                      Element = 'element'

                                                        member End

                                                        End = 'end'

                                                          member Equals

                                                          Equals = 'equals'

                                                            member Exists

                                                            Exists = 'exists'

                                                              member Hyphen

                                                              Hyphen = 'hyphen'

                                                                member Not

                                                                Not = 'not'

                                                                  member Start

                                                                  Start = 'start'

                                                                    enum SelectorType

                                                                    enum SelectorType {
                                                                    Attribute = 'attribute',
                                                                    Pseudo = 'pseudo',
                                                                    PseudoElement = 'pseudo-element',
                                                                    Tag = 'tag',
                                                                    Universal = 'universal',
                                                                    Adjacent = 'adjacent',
                                                                    Child = 'child',
                                                                    Descendant = 'descendant',
                                                                    Parent = 'parent',
                                                                    Sibling = 'sibling',
                                                                    ColumnCombinator = 'column-combinator',

                                                                      member Adjacent

                                                                      Adjacent = 'adjacent'

                                                                        member Attribute

                                                                        Attribute = 'attribute'

                                                                          member Child

                                                                          Child = 'child'

                                                                            member ColumnCombinator

                                                                            ColumnCombinator = 'column-combinator'

                                                                              member Descendant

                                                                              Descendant = 'descendant'

                                                                                member Parent

                                                                                Parent = 'parent'

                                                                                  member Pseudo

                                                                                  Pseudo = 'pseudo'

                                                                                    member PseudoElement

                                                                                    PseudoElement = 'pseudo-element'

                                                                                      member Sibling

                                                                                      Sibling = 'sibling'

                                                                                        member Tag

                                                                                        Tag = 'tag'

                                                                                          member Universal

                                                                                          Universal = 'universal'

                                                                                            Type Aliases

                                                                                            type DataType

                                                                                            type DataType = Selector[][] | null | string;

                                                                                              type Selector

                                                                                              type Selector =
                                                                                              | PseudoSelector
                                                                                              | PseudoElement
                                                                                              | AttributeSelector
                                                                                              | TagSelector
                                                                                              | UniversalSelector
                                                                                              | Traversal;

                                                                                                type TraversalType

                                                                                                type TraversalType =
                                                                                                | SelectorType.Adjacent
                                                                                                | SelectorType.Child
                                                                                                | SelectorType.Descendant
                                                                                                | SelectorType.Parent
                                                                                                | SelectorType.Sibling
                                                                                                | SelectorType.ColumnCombinator;

                                                                                                  Package Files (4)

                                                                                                  Dependencies (0)

                                                                                                  No dependencies.

                                                                                                  Dev Dependencies (11)

                                                                                                  Peer Dependencies (0)

                                                                                                  No peer dependencies.


                                                                                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/css-what.

                                                                                                  • Markdown
                                                                                                  • HTML
                                                                                                    <a href="https://www.jsdocs.io/package/css-what"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>