您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

51 行
2.1 KiB

4 年前
  1. # css-what [![Build Status](https://secure.travis-ci.org/fb55/css-what.svg?branch=master)](http://travis-ci.org/fb55/css-what)
  2. a CSS selector parser
  3. ## Example
  4. ```js
  5. require('css-what')('foo[bar]:baz')
  6. ~> [ [ { type: 'tag', name: 'foo' },
  7. { type: 'attribute',
  8. name: 'bar',
  9. action: 'exists',
  10. value: '',
  11. ignoreCase: false },
  12. { type: 'pseudo',
  13. name: 'baz',
  14. data: null } ] ]
  15. ```
  16. ## API
  17. __`CSSwhat(selector, options)` - Parses `str`, with the passed `options`.__
  18. The 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:
  19. name | attributes | example | output
  20. ---- | ---------- | ------- | ------
  21. `tag`| `name` | `div` | `{ type: 'tag', name: 'div' }`
  22. `universal`| - | `*` | `{ type: 'universal' }`
  23. `pseudo`| `name`, `data`|`:name(data)`| `{ type: 'pseudo', name: 'name', data: 'data' }`
  24. `pseudo`| `name`, `data`|`:name`| `{ type: 'pseudo', name: 'name', data: null }`
  25. `pseudo-element`| `name` |`::name`| `{ type: 'pseudo-element', name: 'name' }`
  26. `attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr]`|`{ type: 'attribute', name: 'attr', action: 'exists', value: '', ignoreCase: false }`
  27. `attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr=val]`|`{ type: 'attribute', name: 'attr', action: 'equals', value: 'val', ignoreCase: false }`
  28. `attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr^=val]`|`{ type: 'attribute', name: 'attr', action: 'start', value: 'val', ignoreCase: false }`
  29. `attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr$=val]`|`{ type: 'attribute', name: 'attr', action: 'end', value: 'val', ignoreCase: false }`
  30. `child`| - | `>` | `{ type: 'child' }`
  31. `parent`| - | `<` | `{ type: 'parent' }`
  32. `sibling`| - | `~` | `{ type: 'sibling' }`
  33. `adjacent`| - | `+` | `{ type: 'adjacent' }`
  34. `descendant`| - | | `{ type: 'descendant' }`
  35. __Options:__
  36. - `xmlMode`: When enabled, tag names will be case-sensitive (meaning they won't be lowercased).
  37. ---
  38. License: BSD-2-Clause