11[ ![ playground] (https://img.shields.io/badge/playground-try%20it%20now-%230a7398
22)] ( https://tbela99.github.io/css-parser/playground/ ) [ ![ npm] ( https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Ftbela99%2Fcss-parser%2Fmaster%2Fpackage.json&query=version&logo=npm&label=npm&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40tbela99%2Fcss-parser )] ( https://www.npmjs.com/package/@tbela99/css-parser ) [ ![ npm] (https://img.shields.io/jsr/v/%40tbela99/css-parser?link=https%3A%2F%2Fjsr.io%2F%40tbela99%2Fcss-parser
3- )] ( https://jsr.io/@tbela99/css-parser ) [ ![ cov] ( https://tbela99.github.io/css-parser/badges/coverage.svg )] ( https://github.com/tbela99/css-parser/actions ) [ ![ NPM Downloads] ( https://img.shields.io/npm/dm/%40tbela99%2Fcss-parser )] ( https://www.npmjs.com/package/@tbela99/css-parser ) [ ![ bundle size] ( https://img.shields.io/bundlejs/size/%40tbela99/css-parser%400.9.0?exports=cjs )] ( https://www.npmjs.com/package/@tbela99/css-parser )
3+ )] ( https://jsr.io/@tbela99/css-parser ) [ ![ cov] ( https://tbela99.github.io/css-parser/badges/coverage.svg )] ( https://github.com/tbela99/css-parser/actions ) [ ![ Doc ] ( https://img.shields.io/badge/online-documentation-blue )] ( https://tbela99.github.io/css-parser/docs ) [ ![ NPM Downloads] ( https://img.shields.io/npm/dm/%40tbela99%2Fcss-parser )] ( https://www.npmjs.com/package/@tbela99/css-parser ) [ ![ bundle size] ( https://img.shields.io/bundlejs/size/%40tbela99/css-parser%400.9.0?exports=cjs )] ( https://www.npmjs.com/package/@tbela99/css-parser )
44
55# css-parser
66
@@ -97,7 +97,7 @@ Javascript module from cdn
9797
9898<script type =" module" >
9999
100- import {transform } from ' https://esm.sh/@tbela99/css-parser@1.3.0 /web' ;
100+ import {transform } from ' https://esm.sh/@tbela99/css-parser@1.3.1 /web' ;
101101
102102
103103 const css = `
@@ -116,7 +116,7 @@ Javascript module
116116
117117``` javascript
118118
119- < script src= " dist/web/index .js" type= " module" >< / script>
119+ < script src= " dist/web.js" type= " module" >< / script>
120120```
121121
122122Single Javascript file
@@ -134,7 +134,9 @@ Parse and render css in a single pass.
134134
135135``` typescript
136136
137- transform (css , transformOptions : TransformOptions = {}): TransformResult
137+ transform (css : string | ReadableStream < string > , transformOptions : TransformOptions = {}): TransformResult
138+ parse (css : string | ReadableStream < string > , parseOptions : ParseOptions = {}): ParseResult ;
139+ render (ast : AstNode , renderOptions : RenderOptions = {}): RenderResult ;
138140```
139141
140142### Example
@@ -146,6 +148,21 @@ import {transform} from '@tbela99/css-parser';
146148const {ast , code , map , errors , stats } = await transform (css, {minify: true , resolveImport: true , cwd: ' files/css' });
147149```
148150
151+ ### Example
152+
153+ Read from stdin with node using readable stream
154+
155+ ``` typescript
156+ import {transform } from " ../src/node" ;
157+ import {Readable } from " node:stream" ;
158+ import type {TransformResult } from ' ../src/@types/index.d.ts' ;
159+
160+ const readableStream: ReadableStream <string > = Readable .toWeb (process .stdin ) as ReadableStream <string >;
161+ const result: TransformResult = await transform (readableStream , {beautify: true });
162+
163+ console .log (result .code );
164+ ```
165+
149166### TransformOptions
150167
151168Include ParseOptions and RenderOptions
@@ -215,17 +232,17 @@ Include ParseOptions and RenderOptions
215232 - true: same as ColorType.HEX
216233 - false: no color conversion
217234 - ColorType.HEX
218- - ColorType.RGB/ ColorType.RGBA
235+ - ColorType.RGB or ColorType.RGBA
219236 - ColorType.HSL
220237 - ColorType.HWB
221- - ColorType.CMYK/ ColorType.DEVICE_CMYK
238+ - ColorType.CMYK or ColorType.DEVICE_CMYK
222239 - ColorType.SRGB
223240 - ColorType.SRGB_LINEAR
224241 - ColorType.DISPLAY_P3
225242 - ColorType.PROPHOTO_RGB
226243 - ColorType.A98_RGB
227244 - ColorType.REC2020
228- - ColorType.XYZ/ ColorType.XYZ_D65
245+ - ColorType.XYZ or ColorType.XYZ_D65
229246 - ColorType.XYZ_D50
230247 - ColorType.LAB
231248 - ColorType.LCH
@@ -903,8 +920,8 @@ const options: ParserOptions = {
903920 nam: ' width' ,
904921 val: [
905922 <LengthToken >{
906- typ: EnumToken .Length ,
907- val: ' 3 ' ,
923+ typ: EnumToken .LengthTokenType ,
924+ val: 3 ,
908925 unit: ' px'
909926 }
910927 ]
@@ -989,7 +1006,8 @@ const options: ParserOptions = {
9891006
9901007 media : (node : AstAtRule ): AstAtRule => {
9911008
992- return {... node , val: ' all' }
1009+ node .val = ' all' ;
1010+ return node
9931011 }
9941012 }
9951013 }
0 commit comments