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
Copy file name to clipboardExpand all lines: docs/Parser.md
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
The parser converts CSS value strings into an Abstract Syntax Tree (AST). It uses [css-tree](https://github.com/csstree/csstree) under the hood, then maps css-tree nodes to this package’s node classes.
4
4
5
-
## parse(css)
5
+
## parse(css, options?)
6
6
7
-
Converts a CSS value string into an AST with a `Root` node.
7
+
Converts a CSS value string into an AST with a `Root` node. The optional `options` argument is accepted for forward‑compatibility in v7 but is currently ignored.
8
8
9
9
### Parameters
10
10
@@ -13,6 +13,7 @@ Converts a CSS value string into an AST with a `Root` node.
13
13
Type: `string` (required)
14
14
15
15
Any valid CSS value string, such as:
16
+
16
17
-`10px solid red`
17
18
-`calc(100% - 20px)`
18
19
-`rgba(255, 0, 0, 0.5)`
@@ -68,12 +69,14 @@ Unknown or unrecognized node types are parsed as `Word` nodes to ensure the pars
68
69
#### Source mapping
69
70
70
71
The parser preserves source locations from the original CSS string, including:
72
+
71
73
- Line and column positions
72
74
- Start and end offsets
73
75
- Original source text
74
76
75
77
```js
76
78
import { parse } from'postcss-values-parser';
79
+
77
80
constroot=parse('calc(100px + 20%)');
78
81
// Each node maintains source position information
Copy file name to clipboardExpand all lines: docs/README.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,21 @@ Please see the [Exports](./Exports.md) documentation for further information.
16
16
17
17
Parsing is powered by [css-tree](https://github.com/csstree/csstree). Nodes in this package extend PostCSS `Node`/`Container`/`Root` so the API feels familiar, but there is no PostCSS parser involved.
18
18
19
-
> Note: This package is ESM‑only. Use `import` syntax in Node.js. If you must use CommonJS, load it via dynamic import: `const mod = await import('postcss-values-parser')`.
19
+
> Note: This package is ESM‑only. Prefer `import` in Node.js. For CommonJS on Node >= 20.19.0 you can use:
0 commit comments