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(tokenizeCSS(cssText)) // an array of CSSTokens
72
-
73
-
</script>
74
-
```
75
-
76
63
## How it works
77
64
78
65
The CSS tokenizer separates a string of CSS into tokens.
@@ -82,58 +69,43 @@ interface CSSToken {
82
69
/** Position in the string at which the token was retrieved. */
83
70
tick:number
84
71
85
-
/** Number identifying the kind of token. */
86
-
type:
87
-
|1// Symbol
88
-
|2// Comment
89
-
|3// Space
90
-
|4// Word
91
-
|5// Function
92
-
|6// Atword
93
-
|7// Hash
94
-
|8// String
95
-
|9// Number
96
-
97
-
/** Code, like the character code of a symbol, or the character code of the opening parenthesis of a function. */
98
-
code:number
99
-
100
-
/** Lead, like the opening of a comment, the quotation mark of a string, or the name of a function. */
101
-
lead:string,
102
-
103
-
/** Data, like the numbers before a unit, the word after an at-sign, or the opening parenthesis of a Function. */
104
-
data:string,
105
-
106
-
/** Tail, like the unit after a number, or the closing of a comment. */
107
-
tail:string,
72
+
/** Number identifying the kind of token; or the character code of a symbol. */
73
+
type:number
74
+
75
+
/** Data, the number of characters in the token. */
76
+
data:number,
77
+
78
+
/** Tail, the number of characters in a unit after a number, or in the closing of a comment. */
79
+
edge:string,
108
80
}
109
81
```
110
82
111
83
As an example, the CSS string `@media` would become a **Atword** token where `@` and `media` are recognized as distinct parts of that token. As another example, the CSS 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`).
112
84
113
85
## Benchmarks
114
86
115
-
As of August 23, 2021, these benchmarks were averaged from my local machine:
87
+
As of April 11, 2022, these benchmarks were reported from my local machine:
0 commit comments