ParserLib is a CSS3 SAX-inspired parser written in JavaScript, designed for event-driven parsing of CSS stylesheets. It supports standard CSS syntax and offers a degree of validation for property names and values, though it is not exhaustive. The library is currently at version 1.1.1, with its most recent update focused on build file regeneration and minor CSS3 feature additions like `turn` units and nested media query support. Unlike AST-based parsers, ParserLib emits events during the parsing process rather than constructing a syntax tree, requiring developers to implement listeners for desired functionalities. It is built to operate in various JavaScript environments, including Node.js, Rhino, and directly in HTML pages, making it versatile for different project setups.
npm install parserlibVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing the CSS parser with 'starHack' and 'underscoreHack' options and parsing a sample CSS string. It highlights the event-driven nature where no AST is returned directly.
Review project-specific changelogs or GitHub releases for `v1.0.0` if available, and adapt code to the updated API. Implement comprehensive tests to identify regressions.
Instead of expecting a return value with a parse tree, register event listeners for specific CSS constructs (e.g., `startstylesheet`, `property`, `rule`) to capture and process information as it's parsed. Example: `parser.addListener('property', (event) => { /* ... */ });`For strict CSS validation requirements, integrate additional dedicated CSS validation tools alongside ParserLib. Do not rely solely on ParserLib for comprehensive syntax or semantic checks.
In Node.js environments, use `const parserlib = require('parserlib');`. For browser use, ensure the `parserlib.js` script is loaded via a `<script>` tag. For modern ESM projects, a bundler or manual CommonJS-to-ESM conversion might be necessary.For client-side parsing of substantial CSS, consider processing in Web Workers to offload the main thread, or pre-process CSS on the server-side.
Examine the CSS content at the reported line and column, and correct the syntax. Consider enabling `strict: false` option during parser initialization for basic error recovery, although it may not resolve all issues.
Ensure `require('parserlib')` successfully loads the module. Verify that the script loading order is correct in browser environments if using `<script>` tags, or that the bundler configuration is correct for CommonJS modules.For browser usage, include `parserlib.js` via a `<script>` tag. If using a module system in the browser, ensure your bundler (e.g., Webpack, Rollup) is configured to handle CommonJS modules.
No dependency data recorded yet.