Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanve/reap-css
CSS AST traversal filters
https://github.com/ryanve/reap-css
ast css javascript nodejs traversal
Last synced: about 1 month ago
JSON representation
CSS AST traversal filters
- Host: GitHub
- URL: https://github.com/ryanve/reap-css
- Owner: ryanve
- License: isc
- Created: 2017-06-14T04:41:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-28T19:03:51.000Z (over 7 years ago)
- Last Synced: 2024-10-06T13:35:56.759Z (about 1 month ago)
- Topics: ast, css, javascript, nodejs, traversal
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/reap-css
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# reap-css
CSS AST traversal filters designed for CSS parsed by [`read-css`](https://www.npmjs.com/package/read-css) or [`css.parse`](https://www.npmjs.com/package/css)## install
```
npm install reap-css
```## usage
```js
const reap = require('reap-css')
const read = require('read-css')
const tree = read("test.css")
const harvest = reap(tree)harvest.selectors() // [".apple", ".orange", "button:enabled", ".flex\\@portrait"]
harvest.properties() // ["color", "border-radius", "color", "cursor", "display"]
harvest.media() // ["(color), (update)", "(orientation: portrait)"]
```## methods
### `.selectors()`
Collect array of selectors.
```js
reap(tree).selectors()
```### `.properties()`
Collect array of properties.
```js
reap(tree).properties()
```### `.media()`
Collect array of media queries.
```js
reap(tree).media()
```### `.collect(key)`
Collect array of values.
```js
reap(tree).collect("selectors")
```### `.having(key)`
Get array of AST nodes having the specified key
```js
reap(tree).having("media")
```### `.type(type)`
Get array of AST nodes with the specified type.
```js
reap(tree).type("rule")
```## traversal
Reap uses [traverse](https://www.npmjs.com/package/traverse) to travese the AST. The traversal instance for the current tree is accessible via `.traversal`
```js
reap(tree).traversal
```## develop
```
npm install
npm test
npm run demo
```