@@ -24,21 +24,22 @@ $ deno add @tbela99/css-parser
2424
2525- no dependency
2626- CSS validation based upon mdn-data
27- - fault-tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
27+ - CSS modules support
28+ - fault-tolerant parser implementing the CSS syntax module 3 recommendations.
2829- fast and efficient minification without unsafe transforms,
2930 see [ benchmark] ( https://tbela99.github.io/css-parser/benchmark/index.html )
30- - minify colors: color(), lab(), lch(), oklab(), oklch(), color-mix(), light-dark(), system colors and
31+ - colors minification : color(), lab(), lch(), oklab(), oklch(), color-mix(), light-dark(), system colors and
3132 relative color
32- - generate nested css rules
33- - convert nested css rules to legacy syntax
34- - convert colors to any supported color format
35- - generate sourcemap
36- - compute css shorthands. see supported properties list below
37- - minify css transform functions
38- - evaluate math functions: calc(), clamp(), min(), max(), etc.
39- - inline css variables
40- - remove duplicate properties
41- - flatten @import rules
33+ - color conversion to any supported color format
34+ - automatic nested css rules generation
35+ - nested css rules conversion to legacy syntax
36+ - sourcemap generation
37+ - css shorthands computation . see the supported properties list below
38+ - css transform functions minification
39+ - css math functions evaluation : calc(), clamp(), min(), max(), etc.
40+ - css variables inlining
41+ - duplicate properties removal
42+ - @import rules flattening
4243- experimental CSS prefix removal
4344
4445## Online documentation
@@ -49,11 +50,11 @@ See the full documentation at the [CSS Parser](https://tbela99.github.io/css-par
4950
5051Try it [ online] ( https://tbela99.github.io/css-parser/playground/ )
5152
52- ## Exports
53+ ## Import
5354
5455There are several ways to import the library into your application.
5556
56- ### Node exports
57+ ### Node
5758
5859import as a module
5960
@@ -64,7 +65,7 @@ import {transform} from '@tbela99/css-parser';
6465// ...
6566```
6667
67- ### Deno exports
68+ ### Deno
6869
6970import as a module
7071
@@ -84,7 +85,7 @@ const {transform} = require('@tbela99/css-parser/cjs');
8485// ...
8586```
8687
87- ### Web export
88+ ### Web
8889
8990Programmatic import
9091
@@ -162,19 +163,27 @@ Javascript umd module from cdn
162163 </script >
163164```
164165
165- ## Transform
166-
167- Parse and render css in a single pass.
166+ ## Exported functions
168167
169- ### Usage
168+ ``` ts
170169
171- ``` typescript
170+ /* parse and render css */
171+ transform (css : string | ReadableStream < string > , options ?: TransformOptions = {}): Promise < TransformResult >
172+ /* parse css */
173+ parse (css : string | ReadableStream < string > , options ?: ParseOptions = {}): Promise < ParseResult > ;
174+ /* render ast */
175+ render (ast : AstNode , options ?: RenderOptions = {}): RenderResult ;
176+ /* parse and render css file or url */
177+ transformFile (filePathOrUrl : string , options ?: TransformOptions = {}, asStream ?: boolean ): Promise < TransformResult > ;
178+ /* parse css file or url */
179+ parseFile (filePathOrUrl : string , options ?: ParseOptions = {}, asStream ?: boolean ): Promise < ParseResult > ;
172180
173- transform (css : string | ReadableStream < string > , transformOptions : TransformOptions = {}): TransformResult
174- parse (css : string | ReadableStream < string > , parseOptions : ParseOptions = {}): ParseResult ;
175- render (ast : AstNode , renderOptions : RenderOptions = {}): RenderResult ;
176181```
177182
183+ ## Transform
184+
185+ Parse and render css in a single pass.
186+
178187### Example
179188
180189``` javascript
@@ -208,7 +217,7 @@ Include ParseOptions and RenderOptions
208217> Minify Options
209218
210219- minify: boolean, optional. default to _ true_ . optimize ast.
211- - pass: number, optional. minification pass . default to 1
220+ - pass: number, optional. minification passes . default to 1
212221- nestingRules: boolean, optional. automatically generated nested rules.
213222- expandNestingRules: boolean, optional. convert nesting rules into separate rules. will automatically set nestingRules
214223 to false.
@@ -220,6 +229,10 @@ Include ParseOptions and RenderOptions
220229 in the : root {} or html {} rule.
221230- removeEmpty: boolean, optional. remove empty rule lists from the ast.
222231
232+ > CSS modules Options
233+
234+ - module: boolean | ModuleCaseTransformEnum | ModuleScopeEnumOptions | ModuleOptions, optional. css modules options.
235+
223236> CSS Prefix Removal Options
224237
225238- removePrefix: boolean, optional. remove CSS prefixes.
@@ -895,7 +908,7 @@ for (const {node, parent, root} of walk(ast)) {
895908
896909Ast can be transformed using node visitors
897910
898- ### Exemple 1: Declaration
911+ ### Example 1: Declaration
899912
900913the visitor is called for any declaration encountered
901914
@@ -930,7 +943,7 @@ console.debug(result.code);
930943// .foo{transform:scale(calc(40/3))}
931944```
932945
933- ### Exemple 2: Declaration
946+ ### Example 2: Declaration
934947
935948the visitor is called only on 'height' declarations
936949
@@ -985,7 +998,7 @@ console.debug(result.code);
985998
986999```
9871000
988- ### Exemple 3: At-Rule
1001+ ### Example 3: At-Rule
9891002
9901003the visitor is called on any at-rule
9911004
@@ -1027,7 +1040,7 @@ console.debug(result.code);
10271040
10281041```
10291042
1030- ### Exemple 4: At-Rule
1043+ ### Example 4: At-Rule
10311044
10321045the visitor is called only for at-rule media
10331046
@@ -1069,7 +1082,7 @@ console.debug(result.code);
10691082
10701083```
10711084
1072- ### Exemple 5: Rule
1085+ ### Example 5: Rule
10731086
10741087the visitor is called on any Rule
10751088
@@ -1105,7 +1118,7 @@ console.debug(result.code);
11051118
11061119```
11071120
1108- ### Exemple 6: Rule
1121+ ### Example 6: Rule
11091122
11101123Adding declarations to any rule
11111124
0 commit comments