{"library":"parseley","title":"Parseley: CSS Selectors Parser","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install parseley"],"cli":null},"imports":["import { parse1 } from 'parseley';","import { serialize } from 'parseley';","import { normalize } from 'parseley';","import * as parseley from 'parseley';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { parse1, serialize, normalize } from 'parseley';\nimport { inspect } from 'node:util';\n\nconst str = 'div#id1 > .class2.class1[attr1]';\n\n// Parse the CSS selector string into an AST\nconst ast = parse1(str);\nconsole.log('Parsed AST:', inspect(ast, { breakLength: 45, depth: null }));\n\n// Serialize the AST back into a CSS selector string\nconst serialized = serialize(ast);\nconsole.log(`Serialized: '${serialized}'`);\n\n// Normalize the AST (e.g., reorder simple selectors) and then serialize again\nnormalize(ast);\nconst normalized = serialize(ast);\nconsole.log(`Normalized: '${normalized}'`);\n","lang":"typescript","description":"Demonstrates how to parse a CSS selector string into an AST, serialize the AST back to a string, and normalize the AST structure.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}