1673b72284644919cfd068b0b824ca981680ece4daad1ac35ad337ca138395e8e8d80b8a4c984282ef144e6f3c118eb6371e74a47c45bdbbb164b000e8f7f6 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # postcss-selector-parser [![test](https://github.com/postcss/postcss-selector-parser/actions/workflows/test.yml/badge.svg)](https://github.com/postcss/postcss-selector-parser/actions/workflows/test.yml)
  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