Skip to content

Commit a718e8c

Browse files
authored
Merge pull request #101 from tbela99/feature/doc
add parseFile(), transformFile() and parse input from readable stream
2 parents 04525dd + 8df9f0a commit a718e8c

File tree

297 files changed

+114391
-5047
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+114391
-5047
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/test/ export-ignore
22
/docs/ export-ignore
3+
/typedoc.json export-ignore
4+
/docs/ export-ignore
5+
/.typedoc-tsconfig.jsonc export-ignore
36
/.editorconfig export-ignore
47
/build.sh export-ignore linguist-vendored
58
/Writerside export-ignore linguist-vendored

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
/.idea
55
/.DS_Store
66
/ROADMAP.md
7-
/docs
87
/package-lock.json
98
test/*.ts
109
test/*.js

.npmignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
/validator
2020
/sw.js
2121
/jsr.json
22-
/.editorconfig
22+
/.editorconfig
23+
/typedoc-tsconfig.jsonc
24+
/typedoc.json
25+
/docs

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.3.1
4+
5+
- [x] generate documentation
6+
- [x] parse input from readable stream
7+
- [x] add parseFile() and transformFile()
8+
-
39
## v1.3.0
410

511
- [x] numerical and dimension tokens use numbers instead of string

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

122122
Single 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';
146148
const {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

151168
Include 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
}

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ do
1010
done
1111
# delete extra .d.ts files in dist/ sub directories
1212
find dist/lib | grep .d.ts | xargs rm
13-
find dist/node | grep .d.ts | xargs rm
14-
find dist/web | grep .d.ts | xargs rm
13+
rm dist/node.d.ts
14+
rm dist/web.d.ts

0 commit comments

Comments
 (0)