1- # css-what [ ![ Build Status ] ( https://secure.travis-ci.org/fb55/css-what.svg?branch=master )] ( http://travis-ci.org/fb55/css-what )
1+ # css-what
22
3- a CSS selector parser
3+ [ ![ Build Status] ( https://img.shields.io/github/workflow/status/fb55/css-what/Node.js%20CI/master )] ( https://github.com/fb55/css-what/actions/workflows/nodejs-test.yml )
4+ [ ![ Coverage] ( https://img.shields.io/coveralls/github/fb55/css-what/master )] ( https://coveralls.io/github/fb55/css-what?branch=master )
5+
6+ A CSS selector parser.
47
58## Example
69
710``` js
8- const CSSwhat = require (" css-what" )
11+ import * as CSSwhat from " css-what" ;
12+
913CSSwhat .parse (" foo[bar]:baz" )
1014
1115~ > [
@@ -16,7 +20,7 @@ CSSwhat.parse("foo[bar]:baz")
1620 name: " bar" ,
1721 action: " exists" ,
1822 value: " " ,
19- ignoreCase: false
23+ ignoreCase: null
2024 },
2125 { type: " pseudo" , name: " baz" , data: null }
2226 ]
@@ -25,32 +29,27 @@ CSSwhat.parse("foo[bar]:baz")
2529
2630## API
2731
28- ** ` CSSwhat.parse(selector, options ) ` - Parses ` selector ` , optionally with the passed ` options ` .**
32+ ** ` CSSwhat.parse(selector) ` - Parses ` selector ` .**
2933
3034The function returns a two-dimensional array. The first array represents selectors separated by commas (eg. ` sub1, sub2 ` ), the second contains the relevant tokens for that selector. Possible token types are:
3135
32- | name | properties | example | output |
33- | ---------------- | --------------------------------------- | ------------- | ---------------------------------------------------------------------------------------- |
34- | ` tag ` | ` name ` | ` div ` | ` { type: 'tag', name: 'div' } ` |
35- | ` universal ` | - | ` * ` | ` { type: 'universal' } ` |
36- | ` pseudo ` | ` name ` , ` data ` | ` :name(data) ` | ` { type: 'pseudo', name: 'name', data: 'data' } ` |
37- | ` pseudo ` | ` name ` , ` data ` | ` :name ` | ` { type: 'pseudo', name: 'name', data: null } ` |
38- | ` pseudo-element ` | ` name ` | ` ::name ` | ` { type: 'pseudo-element', name: 'name' } ` |
39- | ` attribute ` | ` name ` , ` action ` , ` value ` , ` ignoreCase ` | ` [attr] ` | ` { type: 'attribute', name: 'attr', action: 'exists', value: '', ignoreCase: false } ` |
40- | ` attribute ` | ` name ` , ` action ` , ` value ` , ` ignoreCase ` | ` [attr=val] ` | ` { type: 'attribute', name: 'attr', action: 'equals', value: 'val', ignoreCase: false } ` |
41- | ` attribute ` | ` name ` , ` action ` , ` value ` , ` ignoreCase ` | ` [attr^=val] ` | ` { type: 'attribute', name: 'attr', action: 'start', value: 'val', ignoreCase: false } ` |
42- | ` attribute ` | ` name ` , ` action ` , ` value ` , ` ignoreCase ` | ` [attr$=val] ` | ` { type: 'attribute', name: 'attr', action: 'end', value: 'val', ignoreCase: false } ` |
43- | ` child ` | - | ` > ` | ` { type: 'child' } ` |
44- | ` parent ` | - | ` < ` | ` { type: 'parent' } ` |
45- | ` sibling ` | - | ` ~ ` | ` { type: 'sibling' } ` |
46- | ` adjacent ` | - | ` + ` | ` { type: 'adjacent' } ` |
47- | ` descendant ` | - | | ` { type: 'descendant' } ` |
48-
49- ** Options:**
50-
51- - ` lowerCaseTags ` : When false, tag names will not be lowercased. Defaults to ` true ` .
52- - ` lowerCaseAttributeNames ` : When false, attribute names will not be lowercased. Defaults to ` true ` .
53- - ` xmlMode ` : When ` true ` , ` xmlMode ` implies both ` lowerCaseTags ` and ` lowerCaseAttributeNames ` are set to ` false ` .
36+ | name | properties | example | output |
37+ | ------------------- | --------------------------------------- | ------------- | ---------------------------------------------------------------------------------------- |
38+ | ` tag ` | ` name ` | ` div ` | ` { type: 'tag', name: 'div' } ` |
39+ | ` universal ` | - | ` * ` | ` { type: 'universal' } ` |
40+ | ` pseudo ` | ` name ` , ` data ` | ` :name(data) ` | ` { type: 'pseudo', name: 'name', data: 'data' } ` |
41+ | ` pseudo ` | ` name ` , ` data ` | ` :name ` | ` { type: 'pseudo', name: 'name', data: null } ` |
42+ | ` pseudo-element ` | ` name ` | ` ::name ` | ` { type: 'pseudo-element', name: 'name' } ` |
43+ | ` attribute ` | ` name ` , ` action ` , ` value ` , ` ignoreCase ` | ` [attr] ` | ` { type: 'attribute', name: 'attr', action: 'exists', value: '', ignoreCase: false } ` |
44+ | ` attribute ` | ` name ` , ` action ` , ` value ` , ` ignoreCase ` | ` [attr=val] ` | ` { type: 'attribute', name: 'attr', action: 'equals', value: 'val', ignoreCase: false } ` |
45+ | ` attribute ` | ` name ` , ` action ` , ` value ` , ` ignoreCase ` | ` [attr^=val] ` | ` { type: 'attribute', name: 'attr', action: 'start', value: 'val', ignoreCase: false } ` |
46+ | ` attribute ` | ` name ` , ` action ` , ` value ` , ` ignoreCase ` | ` [attr$=val] ` | ` { type: 'attribute', name: 'attr', action: 'end', value: 'val', ignoreCase: false } ` |
47+ | ` child ` | - | ` > ` | ` { type: 'child' } ` |
48+ | ` parent ` | - | ` < ` | ` { type: 'parent' } ` |
49+ | ` sibling ` | - | ` ~ ` | ` { type: 'sibling' } ` |
50+ | ` adjacent ` | - | ` + ` | ` { type: 'adjacent' } ` |
51+ | ` descendant ` | - | | ` { type: 'descendant' } ` |
52+ | ` column-combinator ` | - | ` \|\| ` | ` { type: 'column-combinator' } ` |
5453
5554** ` CSSwhat.stringify(selector) ` - Turns ` selector ` back into a string.**
5655
0 commit comments