css-select

  • Version 7.0.0
  • Published
  • 213 kB
  • 5 dependencies
  • BSD-2-Clause license

Install

npm i css-select
yarn add css-select
pnpm add css-select

Overview

a CSS selector compiler/engine

Index

Functions

function compile

compile: <Node, ElementNode extends Node>(
selector: string | Selector[][],
options?: Options<Node, ElementNode>,
context?: Node[] | Node
) => CompiledQuery<Node>;
  • Compiles a selector to an executable function.

    The returned function checks if each passed node is an element. Use _compileUnsafe to skip this check.

    Parameter selector

    Selector to compile.

    Parameter options

    Compilation options.

    Parameter context

    Optional context for the selector.

function is

is: <Node, ElementNode extends Node>(
element: ElementNode,
query: Query<ElementNode>,
options?: Options<Node, ElementNode>
) => boolean;
  • Tests whether or not an element is matched by query. Node The generic Node type for the DOM adapter being used. ElementNode The Node type for elements for the DOM adapter being used.

    Parameter element

    The element to test if it matches the query.

    Parameter query

    can be either a CSS selector string or a compiled query function.

    Parameter options

    options for querying the document.

    Returns

    Whether the element matches the query.

    See Also

    • compile for supported selector queries.

function prepareContext

prepareContext: <Node, ElementNode extends Node>(
elements: Node | Node[],
adapter: Adapter<Node, ElementNode>,
shouldTestNextSiblings?: boolean
) => Node[];
  • Normalize a query context and optionally include next siblings.

    Parameter elements

    Elements to test against sibling-dependent selectors.

    Parameter adapter

    Adapter implementation used for DOM operations.

    Parameter shouldTestNextSiblings

    Whether sibling combinators should include following siblings.

function selectAll

selectAll: <Node, ElementNode extends Node>(
query: Query<ElementNode>,
elements: Node | Node[],
options?: Options<Node, ElementNode>
) => ElementNode[];
  • Node The generic Node type for the DOM adapter being used. ElementNode The Node type for elements for the DOM adapter being used.

    Parameter elems

    Elements to query. If it is an element, its children will be queried.

    Parameter query

    can be either a CSS selector string or a compiled query function.

    Parameter options

    options for querying the document.

    Returns

    All matching elements.

    See Also

    • compile for supported selector queries.

function selectOne

selectOne: <Node, ElementNode extends Node>(
query: Query<ElementNode>,
elements: Node | Node[],
options?: Options<Node, ElementNode>
) => ElementNode;
  • Node The generic Node type for the DOM adapter being used. ElementNode The Node type for elements for the DOM adapter being used.

    Parameter elems

    Elements to query. If it is an element, its children will be queried.

    Parameter query

    can be either a CSS selector string or a compiled query function.

    Parameter options

    options for querying the document.

    Returns

    the first match, or null if there was no match.

    See Also

    • compile for supported selector queries.

Interfaces

interface Options

interface Options<Node, ElementNode extends Node> {}
  • Public query options for css-select.

property adapter

adapter?: Adapter<Node, ElementNode> | undefined;
  • The adapter to use when interacting with the backing DOM structure. By default it uses the domutils module.

property cacheResults

cacheResults?: boolean;
  • Allow css-select to cache results for some selectors, sometimes greatly improving querying performance. Disable this if your document can change in between queries with the same compiled selector. true

property context

context?: Node | Node[];
  • The context of the current query. Used to limit the scope of searches. Can be matched directly using the :scope pseudo-class.

property lowerCaseAttributeNames

lowerCaseAttributeNames?: boolean;
  • Lower-case attribute names. !xmlMode

property lowerCaseTags

lowerCaseTags?: boolean;
  • Lower-case tag names. !xmlMode

property pseudos

pseudos?:
| Record<
string,
string | ((element: ElementNode, value?: string | null) => boolean)
>
| undefined;
  • Pseudo-classes that override the default ones.

    Maps from names to either strings of functions. - A string value is a selector that the element must match to be selected. - A function is called with the element as its first argument, and optional parameters second. If it returns true, the element is selected.

property quirksMode

quirksMode?: boolean;
  • Is the document in quirks mode?

    This will lead to .className and #id being case-insensitive. false

property relativeSelector

relativeSelector?: boolean;
  • Indicates whether to consider the selector as a relative selector.

    Relative selectors that don't include a :scope pseudo-class behave as if they have a :scope prefix (a :scope pseudo-class, followed by a descendant selector).

    If relative selectors are disabled, selectors starting with a traversal will lead to an error. true

    See Also

property rootFunc

rootFunc?: (element: ElementNode) => boolean;
  • The last function in the stack, will be called with the last element that's looked at.

property xmlMode

xmlMode?: boolean;
  • When enabled, tag names will be case-sensitive. false

Package Files (2)

Dependencies (5)

Dev Dependencies (11)

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-select.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/css-select)
  • HTML
    <a href="https://www.jsdocs.io/package/css-select"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>