@aljazmc/syntax 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1
- package/bin/index.js +1305 -16
- package/bin/types/css/ast.d.ts +231 -0
- package/bin/types/css/parser.d.ts +10 -0
- package/bin/types/css/tokens.d.ts +27 -0
- package/bin/types/index.d.ts +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# > syntax
|
|
2
2
|
|
|
3
3
|
Shared, dependency-free scanner and recursive descent parser for JavaScript,
|
|
4
|
-
TypeScript, JSX, JSON, Markdown and
|
|
4
|
+
TypeScript, JSX, JSON, Markdown, HTML and CSS, bundled into `@aljazmc/formatero` and `@aljazmc/lintero`, and published for their
|
|
5
5
|
types.
|
|
6
6
|
|
|
7
7
|
```ts
|
|
@@ -48,3 +48,21 @@ const root = parseHtml('<p class="a">Hi <b>there</b></p>\n');
|
|
|
48
48
|
Element names keep their case, and `tag` is the known tag they match, like
|
|
49
49
|
`div` for `DIV` and `feBlend` for `feBlend`. Scripts, styles and
|
|
50
50
|
preformatted elements keep their content as one raw text.
|
|
51
|
+
|
|
52
|
+
CSS is parsed into rules, at-rules, declarations and their component
|
|
53
|
+
values, and the selectors of rules into compound selectors, combinators
|
|
54
|
+
and simple selectors, like Biome reads them:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { isCss, parseCss } from "@aljazmc/syntax";
|
|
58
|
+
|
|
59
|
+
isCss("styles.css"); // true
|
|
60
|
+
const sheet = parseCss("a > .b:hover { color: red !important; }\n");
|
|
61
|
+
// sheet.children: a Rule, its selectors and a block with a Declaration
|
|
62
|
+
// sheet.comments: every /* */ comment
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Nested rules, `@media` queries and other at-rule preludes keep their
|
|
66
|
+
values, keyframes keep theirs instead of selectors. Errors throw a
|
|
67
|
+
`ParseError`, or with `parseCss(source, { recover: true })` the items
|
|
68
|
+
with errors are skipped and listed in `sheet.errors`.
|