Skip to content

Commit 4beeac4

Browse files
committed
improve docs
1 parent 1e4c3d7 commit 4beeac4

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

packages/css-tokenizer/README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/actions/workflows/test.yml/badge.svg?branch=main" height="20">][cli-url]
55
[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
66

7-
Implemented from : https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/
7+
Implemented from : https://drafts.csswg.org/css-syntax/
88

99
## API
1010

@@ -19,46 +19,46 @@ npm install @csstools/css-tokenizer --save-dev
1919
```
2020

2121
```js
22-
import { tokenizer, TokenType } from '@csstools/css-tokenizer';
22+
import { tokenize } from '@csstools/css-tokenizer';
2323

24-
const myCSS = `@media only screen and (min-width: 768rem) {
24+
const myCSS = `@media only screen and (min-width: 768rem) {
2525
.foo {
2626
content: 'Some content!' !important;
2727
}
2828
}
2929
`;
3030

31-
const t = tokenizer({
31+
const tokens = tokenize({
3232
css: myCSS,
3333
});
3434

35-
while (true) {
36-
const token = t.nextToken();
37-
if (token[0] === TokenType.EOF) {
38-
break;
39-
}
40-
41-
console.log(token);
42-
}
35+
console.log(tokens);
4336
```
4437

45-
Or use the `tokenize` helper function:
38+
Or use the streaming interface:
4639

4740
```js
48-
import { tokenize } from '@csstools/css-tokenizer';
41+
import { tokenizer, TokenType } from '@csstools/css-tokenizer';
4942

50-
const myCSS = `@media only screen and (min-width: 768rem) {
43+
const myCSS = `@media only screen and (min-width: 768rem) {
5144
.foo {
5245
content: 'Some content!' !important;
5346
}
5447
}
5548
`;
5649

57-
const tokens = tokenize({
50+
const t = tokenizer({
5851
css: myCSS,
5952
});
6053

61-
console.log(tokens);
54+
while (true) {
55+
const token = t.nextToken();
56+
if (token[0] === TokenType.EOF) {
57+
break;
58+
}
59+
60+
console.log(token);
61+
}
6262
```
6363

6464
### Options
@@ -93,16 +93,16 @@ while (true) {
9393
Parser errors will try to inform you where in the tokenizer logic the error happened.
9494
This tells you what kind of error occurred.
9595

96-
## Goals and non-goals
96+
## Order of priorities
9797

98-
Things this package aims to be:
99-
- specification compliant CSS tokenizer
100-
- a reliable low level package to be used in CSS parsers
98+
1. specification compliance
99+
2. correctness
100+
3. reliability
101+
4. tokenizing and serializing must round trip losslessly
102+
5. exposing useful aspects about the source code
103+
6. runtime performance
104+
7. package size
101105

102-
What it is not:
103-
- opinionated
104-
- fast
105-
- small
106106

107107
[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
108108
[discord]: https://discord.gg/bUadyRwkJS

0 commit comments

Comments
 (0)