Skip to content

Commit

Permalink
Merge pull request #1 from tbela99/generators
Browse files Browse the repository at this point in the history
rewrite parser
  • Loading branch information
tbela99 committed May 25, 2023
2 parents c9bb5da + ac1e0e1 commit 67a9af7
Show file tree
Hide file tree
Showing 59 changed files with 4,675 additions and 6,796 deletions.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,87 @@
# css-parser

CSS parser for node and the browser

## Installation

```shell
$ npm install @tbela99/css-parser
```

## Parsing

```javascript
import {parse} from '@tbela99/css-parser';

const {ast, errors} = parse(css);
```

### Usage

```javascript

parse(css, parseOptions = {})
```
### parseOptions

- src: string, optional. css file location
- location: boolean, optional. includes node location in the ast
- processImport: boolean, process @import node - not yet implemented
- deduplicate: boolean, remove duplicate node and merge rules
- removeEmpty: boolean, remove empty nodes


## Rendering

### Usage

```javascript
import {render} from '@tbela99/css-parser';

// pretty print
const prettyPrint = render(ast);
// minified
const minified = render(ast, {compress: true})
```

### Rendering options

- compress: boolean, optional. minify output. Also remove comments
- indent: string, optional. indention string. uses space character by default.
- newLine: string, new line character
- removeComments: boolean, remove comments

## Node Walker

```javascript
import {walk} from '@tbela99/css-parser';

for (const node of walk(ast)) {

// do somehting
}
```

## AST

### Comment

- typ: string 'Comment'
- val: string, the comment

### Rule

- typ: string 'Rule'
- sel: string, css selector
- chi: array of children

### AtRule

- typ: string 'AtRule'
- nam: string. AtRule name
- val: rule prelude

### AtRuleStyleSheet

- typ: string 'Stylesheet'
- chi: array of children
105 changes: 0 additions & 105 deletions dist/index.d.ts

This file was deleted.

Loading

0 comments on commit 67a9af7

Please sign in to comment.