Parsel.js is a lightweight and permissive JavaScript library designed for parsing CSS selectors and calculating their specificity. It provides a robust Abstract Syntax Tree (AST) representation of selectors, enabling developers to analyze, manipulate, or traverse selector structures. The current stable version is 1.2.2, with releases occurring relatively frequently, including both patch and minor updates to address bugs and introduce new features like support for relative selector lists. Key differentiators include its minimal footprint and forgiving parsing logic, making it suitable for environments where strict CSS validation might be too restrictive. It also includes built-in functionality for computing the CSS specificity of any given selector.
npm install parsel-jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a complex CSS selector, calculating its specificity, and walking its AST.
Ensure you are using v1.2.1 or later. If locked to v1.2.0, update to v1.2.1 to get the correctly published package.
Ensure your build tooling and environment correctly handle CommonJS modules with the `.cjs` extension. If encountering module resolution errors, check your `tsconfig.json` or bundler configuration.
Upgrade to version 1.0.3 or later to ensure correct parsing of attribute selectors, especially those with quotes or leading/trailing whitespace in values.
Verify that your build system (e.g., Webpack, Rollup) and TypeScript configuration (if applicable) are up-to-date and correctly configured to resolve `parsel-js`. For TypeScript, ensure `moduleResolution` is set appropriately (e.g., `NodeNext` or `Bundler`).
For CommonJS, use `const { parse } = require('parsel-js');`. If you need ESM features in a CommonJS environment, configure your bundler (like Webpack) to transpile `node_modules` or ensure your Node.js version supports ESM via `type: "module"` in `package.json`.Upgrade to `parsel-js` version 1.2.2 or higher, which includes a fix for empty string attribute parsing.
No dependency data recorded yet.