Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
```