You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
consttokens=Array.from(cssTokenizer(cssText)) // an array of css tokens
68
+
57
69
</script>
58
70
```
59
71
60
72
## How it works
61
73
74
+
The CSS tokenizer separates a string of CSS into tokens represented as an array.
75
+
76
+
```ts
77
+
[
78
+
/** Position in the string at which the token was retrieved. */
79
+
number,
80
+
81
+
/** Negative number that identifies the kind of token. */
82
+
number,
83
+
84
+
/** Opening token content, like the opening of a comment or the quotation mark of a string. */
85
+
string,
86
+
87
+
/** Main token content, like the numbers before a unit, or the letters after an at-sign. */
88
+
string,
89
+
90
+
/** Closing token content, like the unit of a number, or the closing of a comment. */
91
+
string,
92
+
]
93
+
```
94
+
62
95
As an example, the string `@media` would become a **Name** token where `@` and `media` are recognized as distinct parts of that token. As another example, the string `5px` would become a **Number** token where `5` and `px` are recognized as distinct parts of that token. As a final example, the string `5px 10px` would become 3 tokens; the **Number** as mentioned before (`5px`), a **Space** token that represents a single space (``), and then another **Number** token (`10px`).
63
96
64
-
An actual token is represented in a series of 5 items;
97
+
An actual token is represented in a series of 5 items;
65
98
66
99
```js
67
-
[0, -9, '', '100', '%'] // CSS with a value of "100%"
100
+
[0, -9, '', '100', '%'] // CSS with a value of "100%"
68
101
```
69
102
70
103
The **first** number represents the position at which the token was read. The **second** number represents the type id of the token. The **third**, **fourth**, and **fifth** strings represent the text prefix, value, and suffix of the token.
0 commit comments