You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

4 years ago
  1. # postcss-selector-parser [![Build Status](https://travis-ci.org/postcss/postcss-selector-parser.svg?branch=master)](https://travis-ci.org/postcss/postcss-selector-parser)
  2. > Selector parser with built in methods for working with selector strings.
  3. ## Install
  4. With [npm](https://npmjs.com/package/postcss-selector-parser) do:
  5. ```
  6. npm install postcss-selector-parser
  7. ```
  8. ## Quick Start
  9. ```js
  10. const parser = require('postcss-selector-parser');
  11. const transform = selectors => {
  12. selectors.walk(selector => {
  13. // do something with the selector
  14. console.log(String(selector))
  15. });
  16. };
  17. const transformed = parser(transform).processSync('h1, h2, h3');
  18. ```
  19. To normalize selector whitespace:
  20. ```js
  21. const parser = require('postcss-selector-parser');
  22. const normalized = parser().processSync('h1, h2, h3', {lossless: false});
  23. // -> h1,h2,h3
  24. ```
  25. Async support is provided through `parser.process` and will resolve a Promise
  26. with the resulting selector string.
  27. ## API
  28. Please see [API.md](API.md).
  29. ## Credits
  30. * Huge thanks to Andrey Sitnik (@ai) for work on PostCSS which helped
  31. accelerate this module's development.
  32. ## License
  33. MIT