UNPKG

1.83 kBMarkdownView Raw
1#CSSwhat [![Build Status](https://secure.travis-ci.org/fb55/CSSwhat.png?branch=master)](http://travis-ci.org/fb55/CSSwhat)
2
3a CSS selector parser
4
5##Example
6
7```js
8require('CSSwhat')('foo[bar]:baz')
9
10~> [ [ { type: 'tag', name: 'foo' },
11 { type: 'attribute',
12 name: 'bar',
13 action: 'exists',
14 value: '',
15 ignoreCase: false },
16 { type: 'pseudo',
17 name: 'baz',
18 data: null } ] ]
19```
20
21##API
22
23__`CSSwhat(selector, options)` - Parses `str`, with the passed `options`.__
24
25The function returns a two-dimensional array. The first array represents subselects separated by commas (eg. `sub1, sub2`), the second contains the relevant tokens for that selector. Possible token types are:
26
27name | attributes | example | output
28---- | ---------- | ------- | ------
29`tag`| `name` | `div` | `{ type: 'tag', name: 'div' }`
30`universal`| - | `*` | `{ type: 'universal' }`
31`pseudo`| `name`, `data`|`:name(data)`| `{ type: 'pseudo', name: 'name', data: 'data' }`
32`pseudo`| `name`, `data`|`:name`| `{ type: 'pseudo', name: 'name', data: null }`
33`attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr]`|`{ type: 'attribute', name: 'attr', action: 'exists', value: '', ignoreCase: false }`
34`attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr=val]`|`{ type: 'attribute', name: 'attr', action: 'equals', value: 'val', ignoreCase: false }`
35`attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr^=val]`|`{ type: 'attribute', name: 'attr', action: 'start', value: 'val', ignoreCase: false }`
36`attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr$=val]`|`{ type: 'attribute', name: 'attr', action: 'end', value: 'val', ignoreCase: false }`
37
38//TODO complete list
39
40__Options:__
41
42- `xmlMode`: When enabled, tagnames will be case-sensitive (ie. the output won't be lowercased).
43
44---
45
46License: BSD-like