Query PostCSS AST with CSS selectors.
Supported selectors are:
-
Type selectors:
rule
,atrule
,decl
,comment
-
Universal selector:
*
-
Attribute selectors:
[attr=value]
,[attr=value]
,[attr~=value]
,[attr|=value]
,[attr^=value]
,[attr$=value]
,[attr*=value]
-
Descendant combinator:
rule decl
-
Child combinator:
atrule > rule
-
Adjacent sibling combinator:
rule + rule
-
General sibling combinator:
rule ~ rule
- Child pseudo classes (
:first-child
,:last-child
,:nth-child
,:nth-last-child
,:only-child
):rule:first-child
- Type pseudo classes (
:first-of-type
,:last-of-type
,:nth-of-type
,:nth-last-of-type
,:only-of-type
):rule:first-of-type
-
Empty nodes:
rule:empty
-
Matches:
:matches(rule, atrule)
-
Negation:
:not(atrule)
In addition to standard selectors, there are also custom selectors:
- Attribute selector with regular expression:
[attr="/^value$/i"]
npm install postcss-query-ast --save
import queryAst from 'postcss-query-ast';
queryAst('rule[selector="body"]').then(( ast ) => {
/* [ Rule {
raws: { before: '\n\t', between: ' ', semicolon: true, after: '\n\t' },
type: 'rule',
nodes: [ [Object] ],
parent:
AtRule { ... },
source: { start: [Object], input: [Object], end: [Object] },
selector: 'body',
lastEach: 11,
indexes: {} } ] */
});
Returns: Promise
Queries PostCSS with CSS selector.
Type: String
CSS selector.
Type: PostCSS.Node
PostCSS AST.
MIT © Ivan Nikolić