Parseley is a JavaScript/TypeScript library designed for parsing CSS selector strings into a structured Abstract Syntax Tree (AST) and for serializing those ASTs back into strings. It also automatically calculates CSS specificity for each selector component. As of version 0.13.1, the library provides core functionalities such as `parse1` for parsing individual selectors, `serialize` for converting an AST back into a CSS string, and `normalize` for standardizing the order of simple selectors within an AST. It ships with comprehensive TypeScript types and is compatible with both Node.js and Deno environments. Parseley's AST structure is optimized for right-to-left processing, representing complex selectors via 'combinator' nodes integrated into 'compound' selectors rather than distinct 'complex selector' nodes. The library maintains a consistent overall AST shape, aiming to simplify client-side processing tasks.
npm install parseleyVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse a CSS selector string into an AST, serialize the AST back to a string, and normalize the AST structure.
Consult the API documentation to identify the function designed for parsing multiple, comma-separated CSS selectors (e.g., `parse`) if your input can contain them. Use `parse1` strictly for individual selector strings.
When traversing or programmatically interacting with the AST, expect combinators to appear as 'combinator' type nodes within 'compound' selector structures, rather than as top-level 'complex selector' nodes. Adapt your AST processing logic to handle `combinator` nodes with their associated `left` and `right` compound selectors.
Migrate your import statements from `const { symbol } = require('parseley');` to `import { symbol } from 'parseley';` to align with ES Module syntax.Ensure you are using named imports for all Parseley functions: `import { parse1, serialize, normalize } from 'parseley';`. If using a namespace import, access via `parseley.parse1`.If your input string contains multiple comma-separated selectors, use the dedicated parsing function for selector lists (e.g., `parse`, if available in the API documentation), or manually split the string by commas and parse each segment individually with `parse1`.
No dependency data recorded yet.