The `css` package is a fundamental JavaScript library designed for robust parsing and stringifying of Cascading Style Sheets (CSS). It serves as a core component for various CSS processing tools, including preprocessors, postprocessors, and linting utilities. At its current stable version, 3.0.0, it offers `css.parse()` to convert raw CSS strings into a detailed Abstract Syntax Tree (AST) object, and `css.stringify()` to transform such an AST back into a minified or formatted CSS string. The library provides comprehensive options for error handling, including a 'silent' mode for collecting parsing errors without throwing, and extensive support for source map generation to maintain traceability between original and processed CSS. Its primary differentiator lies in its adherence to the reworkcss AST specification, offering a consistent and manipulable representation of CSS for complex transformations. While the provided documentation highlights CommonJS usage, modern projects might explore ESM compatibility, though it's not explicitly documented in the given excerpt. The project generally follows semantic versioning without a fixed release cadence.
npm install cssVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing CSS into an AST, stringifying it back, and generating compressed output or sourcemaps using the `css.parse` and `css.stringify` functions.
After calling `css.parse` with `silent: true`, always check `ast.stylesheet.parsingErrors` for any `Error` objects and handle them appropriately.
Pass `source: 'your-filename.css'` as an option to `css.parse` when you intend to generate source maps later with `css.stringify`.
Set `inputSourcemaps: false` in `css.stringify` options if you want to explicitly disable reading external source maps and avoid potential file system I/O.
For reliable module loading in Node.js environments, use `const css = require('css');`. For browser or ES Module-only environments, ensure your build setup correctly handles CommonJS modules or transpile them as needed.Ensure the `css` package is correctly installed (`npm install css`) and that `require('css')` executes successfully. Verify no other variable named `css` is clashing with the imported module.Inspect the CSS at the reported line and column number, and correct any syntax errors. Alternatively, use `options: { silent: true }` in `css.parse` to collect errors in `ast.stylesheet.parsingErrors` instead of throwing them immediately.Verify that the AST structure, especially `node.type` and `node.stylesheet.rules`, is correct and complete. Compare your AST against the output of a known good `css.parse` call or refer to the AST explorer (http://iamdustan.com/reworkcss_ast_explorer/) for validation.
No dependency data recorded yet.