rst-selector-parser is a JavaScript library designed for parsing CSS-like selectors specifically within the context of React Standard Trees (RST). It provides utilities to parse a CSS selector string into an Abstract Syntax Tree (AST) representing the selector's structure, and conversely, to generate a selector string from such an AST. This package is frequently utilized in conjunction with testing libraries like Enzyme for traversing and querying rendered React components. Currently at version 2.2.3, it is a fork of the `scalpel` library, adapted and optimized for the RST environment, ensuring compatibility with its unique traversal needs. Its primary differentiation lies in this specialized focus, offering a robust and programmatic way to interact with component trees using familiar CSS selector syntax, which can be particularly beneficial for testing and introspection workflows in React applications. The last significant update was in late 2019, suggesting a mature but slow-moving maintenance phase.
npm install rst-selector-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a CSS selector into a tokenized AST and then generating a selector string back from the AST.
Ensure you are using this parser in the intended React testing or RST traversal context. For general DOM/HTML CSS parsing, use a dedicated browser or Node.js DOM parser.
Be aware that new features or bug fixes beyond critical issues are unlikely. If you require advanced or very recent CSS selector features, consider alternative, more actively maintained parsing solutions.
For ESM projects, stick to `import { name } from 'pkg';`. For CommonJS projects, use `const { name } = require('pkg');`. Ensure your build tools (e.g., Webpack, Rollup) are configured correctly to handle dual packages.Review the selector string for typos, incorrect combinators, or malformed attributes/pseudo-classes. Consult the W3C CSS3 Selectors specification and the library's `Token types` documentation for supported syntax.
If using an ESM context (e.g., `type: 'module'` in `package.json`), use `import { createParser } from 'rst-selector-parser';`. If explicitly using CommonJS, ensure the `require` statement correctly destructures the named export: `const { createParser } = require('rst-selector-parser');`.No dependency data recorded yet.