css-what

  • Version 8.0.0
  • Published
  • 541 kB
  • No dependencies
  • BSD-2-Clause license

Install

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

Overview

a CSS selector parser

Index

Variables

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.

Functions

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.

    Parameter selector

    Selector to parse.

    Returns

    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.

Interfaces

interface AttributeSelector

interface AttributeSelector {}
  • [attr]-style selector token.

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 {}
              • ::pseudo-element selector token.

              property data

              data: string | null;

                property name

                name: string;

                  property type

                  type: SelectorType.PseudoElement;

                    interface PseudoSelector

                    interface PseudoSelector {}
                    • :pseudo(...) selector token.

                    property data

                    data: DataType;

                      property name

                      name: string;

                        property type

                        type: SelectorType.Pseudo;

                          interface TagSelector

                          interface TagSelector {}
                          • Tag-name selector token.

                          property name

                          name: string;

                            property namespace

                            namespace: string | null;

                              property type

                              type: SelectorType.Tag;

                                interface Traversal

                                interface Traversal {}
                                • Combinator/traversal selector token.

                                property type

                                type: TraversalType;

                                  interface UniversalSelector

                                  interface UniversalSelector {}
                                  • Universal selector token (*).

                                  property namespace

                                  namespace: string | null;

                                    property type

                                    type: SelectorType.Universal;

                                      Enums

                                      enum AttributeAction

                                      enum AttributeAction {
                                      Any = 'any',
                                      Element = 'element',
                                      End = 'end',
                                      Equals = 'equals',
                                      Exists = 'exists',
                                      Hyphen = 'hyphen',
                                      Not = 'not',
                                      Start = 'start',
                                      }
                                      • Operators available for attribute selectors.

                                      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',
                                                      }
                                                      • Discriminants for selector token kinds.

                                                      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;
                                                                            • Payload used by pseudo selectors.

                                                                            type Selector

                                                                            type Selector =
                                                                            | PseudoSelector
                                                                            | PseudoElement
                                                                            | AttributeSelector
                                                                            | TagSelector
                                                                            | UniversalSelector
                                                                            | Traversal;
                                                                            • Any selector token produced by the parser.

                                                                            type TraversalType

                                                                            type TraversalType =
                                                                            | SelectorType.Adjacent
                                                                            | SelectorType.Child
                                                                            | SelectorType.Descendant
                                                                            | SelectorType.Parent
                                                                            | SelectorType.Sibling
                                                                            | SelectorType.ColumnCombinator;
                                                                            • Union of traversal/combinator selector types.

                                                                            Package Files (4)

                                                                            Dependencies (0)

                                                                            No dependencies.

                                                                            Dev Dependencies (9)

                                                                            Peer Dependencies (0)

                                                                            No peer dependencies.

                                                                            Badge

                                                                            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
                                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/css-what)
                                                                            • 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>