-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tbela99/generators
rewrite parser
- Loading branch information
Showing
59 changed files
with
4,675 additions
and
6,796 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.