{"library":"parserlib","title":"ParserLib CSS Parser","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install parserlib"],"cli":null},"imports":["const parserlib = require('parserlib');","const { Parser } = require('parserlib').css;","parser.addListener('property', (event) => console.log(event.property.text));"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const parserlib = require('parserlib');\n\nconst parser = new parserlib.css.Parser({\n  starHack: true, // Treat properties with a leading asterisk as if the asterisk wasn't there\n  underscoreHack: true // Treat properties with a leading underscore as if the underscore wasn't there\n});\n\nconst someCSSText = `\n  /* This is a sample CSS block */\n  @media screen and (min-width: 768px) {\n    .container {\n      width: 90%;\n      margin: 0 auto;\n    }\n  }\n\n  body {\n    font-family: Arial, sans-serif;\n    color: #333;\n  }\n\n  h1._title { /* underscore hack example */\n    font-size: 2em;\n    *color: #00f; /* star hack example, if 'starHack' is true */\n    text-decoration: underline;\n  }\n`;\n\ntry {\n  parser.parse(someCSSText);\n  console.log('CSS parsed successfully. Remember, this is an event-driven parser; attach listeners for detailed output.');\n} catch (e) {\n  console.error('Parsing error:', e.message);\n}","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}