css-select
- Version 5.1.0
- Published
- 224 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
Variables
Functions
function compile
compile: <Node, ElementNode extends Node>( selector: string | import('css-what').Selector[][], options?: Options<Node, ElementNode>, context?: Node | Node[]) => CompiledQuery<Node>;
Compiles the query, returns a function.
function is
is: <Node, ElementNode extends Node>( elem: 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 elem
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
See Also
compile for supported selector queries.
function prepareContext
prepareContext: <Node, ElementNode extends Node>( elems: Node | Node[], adapter: Adapter<Node, ElementNode>, shouldTestNextSiblings?: boolean) => Node[];
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> {}
property adapter
adapter?: Adapter<Node, ElementNode>;
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 | ((elem: 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 (5)
Dependencies (5)
Dev Dependencies (13)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto 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[](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>
- Updated .
Package analyzed in 1400 ms. - Missing or incorrect documentation? Open an issue for this package.