Shady CSS Parser is a JavaScript library designed for fast, small, and flexible runtime parsing and transformation of CSS. It is currently in an early development stage, with the latest stable version being 0.1.0. While it is not fully spec-compliant, it is designed to parse all spec-compliant CSS loosely and efficiently, prioritizing graceful error recovery to handle malformed CSS in a manner similar to browsers. This makes it particularly suitable for scenarios requiring runtime manipulation, such as in tools like Polymer or Polymer Designer. The library ships with TypeScript types and focuses on providing a performant parsing and stringification mechanism, though it notably discards most insignificant whitespace during processing. Its release cadence appears to be iterative with frequent minor updates as indicated by the 0.0.x version progression.
npm install shady-css-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates the basic usage of Shady CSS Parser to parse a CSS string into an AST and then stringify the AST back into a normalized CSS string.
If you are extending or directly using the `Tokenizer` for custom parsing, update calls from `findNextToken()` to `getNextToken()`.
Be aware that the AST or stringified output might not perfectly match highly malformed CSS inputs compared to a strict parser. Test thoroughly if strict spec adherence is critical.
Do not rely on whitespace preservation when using the default stringifier. If exact whitespace preservation is required, custom stringification logic would be necessary, potentially requiring modifications to the AST during parsing to retain whitespace information.
Pin exact versions in your `package.json` (e.g., `"shady-css-parser": "0.1.0"`) and carefully review changelogs for any breaking changes when upgrading.
Ensure your Node.js project's `package.json` contains `"type": "module"` or use a bundler (like Webpack, Rollup) or transpiler (like Babel, TypeScript) for browser or older Node.js environments. Alternatively, manually configure Node to treat files as ESM.
Use a named import: `import { Parser } from 'shady-css-parser';` for ESM. If strictly using CommonJS (not recommended for this library), ensure `const { Parser } = require('shady-css-parser');`.Run `npm install shady-css-parser` or `yarn add shady-css-parser` in your project directory. Double-check the spelling of the package name in your `package.json` and import statements.
No dependency data recorded yet.