{"id":14945,"library":"style-parser","title":"CSS Style Parser","description":"style-parser is a lightweight JavaScript library designed for parsing inline CSS style strings into structured JavaScript objects. It is built upon the `Parsimmon` parser combinator library, providing a robust and pure JavaScript solution for extracting style properties. The library is particularly useful in server-side environments with tools like Cheerio or within browser contexts where direct manipulation of string-based `style` attributes is required. The current stable version is 1.1.1. Its key differentiator is the ability to transform a raw CSS style string, such as `\"font-size:13px;width:50px\"`, into a usable JavaScript object like `{'font-size': '13px', 'width': '50px'}`, which is functionality not natively provided by jQuery or Cheerio's `attr('style')` method. The package's release cadence is not explicitly stated in the provided documentation.","status":"maintenance","version":"1.1.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/weflex/style-parser","tags":["javascript"],"install":[{"cmd":"npm install style-parser","lang":"bash","label":"npm"},{"cmd":"yarn add style-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add style-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core parsing logic is implemented using the Parsimmon parser combinator library.","package":"parsimmon","optional":false}],"imports":[{"note":"The package's primary usage examples and documentation demonstrate CommonJS `require()` syntax. Native ES module `import` syntax may not be directly supported without transpilation or a bundler for this version, as dual package exports are not explicitly mentioned.","wrong":"import parse from 'style-parser';","symbol":"parse","correct":"const parse = require('style-parser');"}],"quickstart":{"code":"const parse = require('style-parser');\nconst cheerio = require('cheerio'); // Install with 'npm install cheerio' for this example\n\n// Basic usage: parse a simple inline style string\nconst styleString = 'font-size:13px;color:blue;';\nconst parsedStyle = parse(styleString);\nconsole.log('Parsed simple style string:', parsedStyle);\n// Expected: { 'font-size': '13px', color: 'blue' }\n\n// Advanced usage: integrate with Cheerio to parse style attributes from HTML\nconst html = '<div style=\"width:100px;height:50px;border:1px solid #ccc;\">Content</div>';\nconst $ = cheerio.load(html);\nconst inlineStyleAttr = $('div').attr('style');\n\nif (inlineStyleAttr) {\n  const parsedCheerioStyle = parse(inlineStyleAttr);\n  console.log('Parsed style attribute from Cheerio element:', parsedCheerioStyle);\n  // Expected: { width: '100px', height: '50px', border: '1px solid #ccc' }\n} else {\n  console.log('No style attribute found on the div element.');\n}\n\n// Handle cases where the style attribute might be undefined or empty\nconst emptyStyleHtml = '<div>No style</div>';\nconst $empty = cheerio.load(emptyStyleHtml);\nconst emptyInlineStyle = $empty('div').attr('style');\nconst parsedEmpty = parse(emptyInlineStyle || ''); // Ensure a string is passed\nconsole.log('Parsed empty or missing style attribute:', parsedEmpty);\n// Expected: {} (or similar empty object if input is null/undefined/empty string)","lang":"javascript","description":"Demonstrates the basic parsing of a CSS style string and a common use case: extracting and parsing inline styles from HTML elements using Cheerio."},"warnings":[],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[],"ecosystem":"npm"}