{"library":"postcss-safe-parser","title":"PostCSS Safe Parser","description":"postcss-safe-parser is a fault-tolerant CSS parser designed specifically for use with PostCSS. It excels at parsing virtually any CSS input, including highly malformed or 'hacky' legacy code often encountered in historical examples or real-world unvalidated user input, and is particularly valuable for applications like live demo tools. The current stable version, 7.0.1, indicates active development and maintenance, typically aligning with the release cadence of the broader PostCSS ecosystem. Its primary differentiator is its robust error recovery mechanism, enabling it to process and recover from CSS syntax errors that would cause standard parsers to fail, thus providing a resilient parsing solution for environments where input validity cannot be guaranteed. It requires Node.js version 18 or higher and `postcss` version `^8.4.31` as a peer dependency.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install postcss-safe-parser"],"cli":null},"imports":["import safeParser from 'postcss-safe-parser'","const safeParser = require('postcss-safe-parser')","postcss([ /* other plugins */ ], { parser: safeParser })"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import postcss from 'postcss';\nimport safeParser from 'postcss-safe-parser';\n\nasync function processUnsafeCss() {\n  const malformedCss = `\n    .bad-class {\n      color: red;\n      font-size: 16px;\n      width: calc(100% - 20px;\n      background: url('missing-quote.png);\n      /* Missing closing brace\n    .another-class { display: block; }\n  `;\n\n  try {\n    const result = await postcss().process(malformedCss, {\n      parser: safeParser,\n      from: undefined // Prevents 'Cannot read properties of undefined' if input source is unknown\n    });\n\n    console.log('Original CSS:\\n', malformedCss);\n    console.log('\\nSuccessfully parsed and stringified CSS:\\n', result.css);\n    console.log('\\nMessages (e.g., warnings/errors handled by parser):\\n', result.messages);\n  } catch (error) {\n    console.error('An unexpected error occurred during processing:', error);\n  }\n}\n\nprocessUnsafeCss();\n","lang":"typescript","description":"Demonstrates how to use `postcss-safe-parser` with `postcss` to parse and process malformed CSS, showcasing its fault-tolerant capabilities.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}