CSS Simple Parser is a highly optimized, lightweight parser for (S)CSS strings, weighing in at approximately 1.5kb (min + gzip). It is designed for blazing-fast performance, benchmarking around 100x faster than PostCSS for typical use cases. Currently at version 3.0.2, the library is actively maintained but adheres to a 'too simple' philosophy, focusing on core rule block parsing. Key differentiators include its small footprint and speed, achieved by intentionally limiting its scope. It supports nested (S)CSS rules but does not handle top-level directives like `@charset` or `@import`, nor does it permit curly braces (`{`, `}`) or semicolons (`;`) within string literals. The Abstract Syntax Tree (AST) it generates is intentionally crude, requiring further processing for complex operations. Its release cadence is feature-driven, with new versions addressing enhancements or bug fixes within its defined scope.
npm install css-simple-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a CSS string with nested rules, traversing the resulting AST to extract selectors, stringifying the AST back into CSS, and then performing a simple AST modification followed by re-stringification.
Ensure your CSS input strictly adheres to the supported syntax (primarily nested rule blocks). For full CSS specification compliance and advanced features, consider using a more comprehensive parser like PostCSS.
Refactor your CSS to avoid these characters within string literals. If your use case absolutely requires them, this parser is not suitable, and an alternative like `css-tree` should be considered.
Be prepared to implement custom logic to process the simplified AST nodes to extract specific information or perform advanced manipulations. If you need a highly detailed or standardized AST, explore libraries like `css-tree` or `PostCSS`.
Modify your CSS to remove `{` or `}` characters from within string values (e.g., `content: "{}"` is invalid). If these characters are essential, `css-simple-parser` cannot be used.Modify your CSS to remove `;` characters from within string values (e.g., `div[attr=";foo"]` is invalid). If necessary, switch to a more robust parser.
Ensure your CSS only contains standard rule blocks (e.g., `.selector { ... }`) or nested rules. If you need to parse full CSS specifications, use a different parsing library.No dependency data recorded yet.