Skip to content

Commit 55c945f

Browse files
committed
docs(v7): Parser header shows forward‑compat signature; clarify CommonJS on Node >=20.19 can require ESM
1 parent af27d8e commit 55c945f

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ npm install postcss-values-parser --save-dev
2727
- Node.js >= 20.19.0
2828
- PostCSS >= 8.4.14 (peer dependency)
2929

30-
Note: This package is ESM‑only. Use `import` in Node.js. In CommonJS on Node.js 20.19.0+ you can `require()` it:
30+
Note: This package is ESM‑only. Use `import` in Node.js. In CommonJS on Node >= 20.19.0 you can `require()` it:
3131

3232
```js
3333
// CommonJS (Node >= 20.19.0)

docs/Parser.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
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.
44

5-
## parse(css)
5+
## parse(css, options?)
66

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
8+
`options` parameter is accepted for forward‑compatibility in v7 but is
9+
currently ignored.
810

911
### Parameters
1012

@@ -13,6 +15,7 @@ Converts a CSS value string into an AST with a `Root` node.
1315
Type: `string` (required)
1416

1517
Any valid CSS value string, such as:
18+
1619
- `10px solid red`
1720
- `calc(100% - 20px)`
1821
- `rgba(255, 0, 0, 0.5)`
@@ -68,12 +71,14 @@ Unknown or unrecognized node types are parsed as `Word` nodes to ensure the pars
6871
#### Source mapping
6972

7073
The parser preserves source locations from the original CSS string, including:
74+
7175
- Line and column positions
7276
- Start and end offsets
7377
- Original source text
7478

7579
```js
7680
import { parse } from 'postcss-values-parser';
81+
7782
const root = parse('calc(100px + 20%)');
7883
// Each node maintains source position information
7984
```
@@ -103,7 +108,7 @@ try {
103108
Thrown when the parsed AST is invalid or empty:
104109

105110
```js
106-
import { parse, AstError } from 'postcss-values-parser';
111+
import { AstError, parse } from 'postcss-values-parser';
107112

108113
try {
109114
const root = parse('');
@@ -122,9 +127,9 @@ The parser creates nodes using the NodeOptions interface:
122127

123128
```typescript
124129
interface NodeOptions {
125-
node?: CssNode; // Original css-tree node
126-
value?: string; // String value
127-
parent?: any; // Parent node
130+
node?: CssNode; // Original css-tree node
131+
value?: string; // String value
132+
parent?: any; // Parent node
128133
}
129134
```
130135

@@ -157,6 +162,7 @@ console.log(calcFunc.nodes.length); // Contains parsed parameters
157162
## Browser and Environment Support
158163

159164
The parser works in all environments where css-tree is supported:
165+
160166
- Node.js (all supported versions)
161167
- Modern browsers (ES2015+)
162168
- Webpack/Rollup bundled applications
@@ -168,7 +174,7 @@ The parser works in all environments where css-tree is supported:
168174

169175
```js
170176
const root = parse('10px solid red');
171-
console.log(root.nodes.map(n => n.type)); // ['numeric', 'word', 'word']
177+
console.log(root.nodes.map((n) => n.type)); // ['numeric', 'word', 'word']
172178
```
173179

174180
### Function Parsing
@@ -184,7 +190,7 @@ console.log(func.isColor); // true
184190

185191
```js
186192
const root = parse('calc(100% - 20px) url("bg.jpg") center/cover');
187-
root.walkFuncs(func => {
193+
root.walkFuncs((func) => {
188194
console.log(`Function: ${func.name}`);
189195
});
190196
```

docs/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ Please see the [Exports](./Exports.md) documentation for further information.
1616

1717
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.
1818

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. Use `import` syntax in Node.js. In CommonJS on Node >= 20.19.0 you can `require()` ESM packages:
20+
>
21+
> ```js
22+
> // CommonJS (Node >= 20.19.0)
23+
> const { parse } = require('postcss-values-parser');
24+
> ```
2025
2126
## Nodes
2227

0 commit comments

Comments
 (0)