Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/test/ export-ignore
/docs/ export-ignore
/typedoc.json export-ignore
/docs/ export-ignore
/.typedoc-tsconfig.jsonc export-ignore
/.editorconfig export-ignore
/build.sh export-ignore linguist-vendored
/Writerside export-ignore linguist-vendored
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/.idea
/.DS_Store
/ROADMAP.md
/docs
/package-lock.json
test/*.ts
test/*.js
Expand Down
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
/validator
/sw.js
/jsr.json
/.editorconfig
/.editorconfig
/typedoc-tsconfig.jsonc
/typedoc.json
/docs
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.3.1

- [x] generate documentation
- [x] parse input from readable stream
- [x] add parseFile() and transformFile()
-
## v1.3.0

- [x] numerical and dimension tokens use numbers instead of string
Expand Down
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![playground](https://img.shields.io/badge/playground-try%20it%20now-%230a7398
)](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
)](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)
)](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)

# css-parser

Expand Down Expand Up @@ -97,7 +97,7 @@ Javascript module from cdn

<script type="module">

import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.0/web';
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.1/web';


const css = `
Expand All @@ -116,7 +116,7 @@ Javascript module

```javascript

<script src="dist/web/index.js" type="module"></script>
<script src="dist/web.js" type="module"></script>
```

Single Javascript file
Expand All @@ -134,7 +134,9 @@ Parse and render css in a single pass.

```typescript

transform(css, transformOptions: TransformOptions = {}): TransformResult
transform(css: string | ReadableStream<string>, transformOptions: TransformOptions = {}): TransformResult
parse(css: string | ReadableStream<string>, parseOptions: ParseOptions = {}): ParseResult;
render(ast: AstNode, renderOptions: RenderOptions = {}): RenderResult;
```

### Example
Expand All @@ -146,6 +148,21 @@ import {transform} from '@tbela99/css-parser';
const {ast, code, map, errors, stats} = await transform(css, {minify: true, resolveImport: true, cwd: 'files/css'});
```

### Example

Read from stdin with node using readable stream

```typescript
import {transform} from "../src/node";
import {Readable} from "node:stream";
import type {TransformResult} from '../src/@types/index.d.ts';

const readableStream: ReadableStream<string> = Readable.toWeb(process.stdin) as ReadableStream<string>;
const result: TransformResult = await transform(readableStream, {beautify: true});

console.log(result.code);
```

### TransformOptions

Include ParseOptions and RenderOptions
Expand Down Expand Up @@ -215,17 +232,17 @@ Include ParseOptions and RenderOptions
- true: same as ColorType.HEX
- false: no color conversion
- ColorType.HEX
- ColorType.RGB/ColorType.RGBA
- ColorType.RGB or ColorType.RGBA
- ColorType.HSL
- ColorType.HWB
- ColorType.CMYK/ColorType.DEVICE_CMYK
- ColorType.CMYK or ColorType.DEVICE_CMYK
- ColorType.SRGB
- ColorType.SRGB_LINEAR
- ColorType.DISPLAY_P3
- ColorType.PROPHOTO_RGB
- ColorType.A98_RGB
- ColorType.REC2020
- ColorType.XYZ/ColorType.XYZ_D65
- ColorType.XYZ or ColorType.XYZ_D65
- ColorType.XYZ_D50
- ColorType.LAB
- ColorType.LCH
Expand Down Expand Up @@ -903,8 +920,8 @@ const options: ParserOptions = {
nam: 'width',
val: [
<LengthToken>{
typ: EnumToken.Length,
val: '3',
typ: EnumToken.LengthTokenType,
val: 3,
unit: 'px'
}
]
Expand Down Expand Up @@ -989,7 +1006,8 @@ const options: ParserOptions = {

media: (node: AstAtRule): AstAtRule => {

return {...node, val: 'all'}
node.val = 'all';
return node
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ do
done
# delete extra .d.ts files in dist/ sub directories
find dist/lib | grep .d.ts | xargs rm
find dist/node | grep .d.ts | xargs rm
find dist/web | grep .d.ts | xargs rm
rm dist/node.d.ts
rm dist/web.d.ts
Loading