@tbela99/css-parser 0.0.1-rc2 → 0.0.1-rc4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ $ npm install @tbela99/css-parser
15
15
  - fault tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
16
16
  - efficient minification, see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
17
17
  - replace @import at-rules with actual css content of the imported rule
18
- - automatically create nested css rules
18
+ - automatically generate nested css rules
19
19
  - works the same way in node and web browser
20
20
 
21
21
  ### Performance
@@ -79,7 +79,7 @@ parse(css, parseOptions = {})
79
79
 
80
80
  ````javascript
81
81
 
82
- const {ast, errors} = await parse(css);
82
+ const {ast, errors, stats} = await parse(css);
83
83
  ````
84
84
 
85
85
  ## Rendering
@@ -96,7 +96,7 @@ render(ast, RenderOptions = {});
96
96
  import {render} from '@tbela99/css-parser';
97
97
 
98
98
  // minified
99
- const {code} = render(ast, {minify: true});
99
+ const {code, stats} = render(ast, {minify: true});
100
100
 
101
101
  console.log(code);
102
102
  ```
@@ -160,6 +160,62 @@ Single JavaScript file
160
160
  <script src="dist/index-umd-web.js"></script>
161
161
  ```
162
162
 
163
+ ## Example
164
+
165
+ ### Automatic CSS Nesting
166
+
167
+ CSS
168
+
169
+ ```css
170
+
171
+ table.colortable td {
172
+ text-align:center;
173
+ }
174
+ table.colortable td.c {
175
+ text-transform:uppercase;
176
+ }
177
+ table.colortable td:first-child, table.colortable td:first-child+td {
178
+ border:1px solid black;
179
+ }
180
+ table.colortable th {
181
+ text-align:center;
182
+ background:black;
183
+ color:white;
184
+ }
185
+ ```
186
+
187
+ Javascript
188
+ ```javascript
189
+ import {parse, render} from '@tbela99/css-parser';
190
+
191
+
192
+ const options = {minify: true, nestingRules: true};
193
+
194
+ const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
195
+ //
196
+ console.debug(code);
197
+ ```
198
+
199
+ Result
200
+ ```css
201
+ table.colortable {
202
+ & td {
203
+ text-align: center;
204
+ &.c {
205
+ text-transform: uppercase
206
+ }
207
+ &:first-child,&:first-child+td {
208
+ border: 1px solid #000
209
+ }
210
+ }
211
+ & th {
212
+ text-align: center;
213
+ background: #000;
214
+ color: #fff
215
+ }
216
+ }
217
+ ```
218
+
163
219
  ## AST
164
220
 
165
221
  ### Comment