Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
parse
✓ const parse = require('style-parser');
✗ import parse from 'style-parser';
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.
Demonstrates the basic parsing of a CSS style string and a common use case: extracting and parsing inline styles from HTML elements using Cheerio.
const parse = require('style-parser');
const cheerio = require('cheerio'); // Install with 'npm install cheerio' for this example
// Basic usage: parse a simple inline style string
const styleString = 'font-size:13px;color:blue;';
const parsedStyle = parse(styleString);
console.log('Parsed simple style string:', parsedStyle);
// Expected: { 'font-size': '13px', color: 'blue' }
// Advanced usage: integrate with Cheerio to parse style attributes from HTML
const html = '<div style="width:100px;height:50px;border:1px solid #ccc;">Content</div>';
const $ = cheerio.load(html);
const inlineStyleAttr = $('div').attr('style');
if (inlineStyleAttr) {
const parsedCheerioStyle = parse(inlineStyleAttr);
console.log('Parsed style attribute from Cheerio element:', parsedCheerioStyle);
// Expected: { width: '100px', height: '50px', border: '1px solid #ccc' }
} else {
console.log('No style attribute found on the div element.');
}
// Handle cases where the style attribute might be undefined or empty
const emptyStyleHtml = '<div>No style</div>';
const $empty = cheerio.load(emptyStyleHtml);
const emptyInlineStyle = $empty('div').attr('style');
const parsedEmpty = parse(emptyInlineStyle || ''); // Ensure a string is passed
console.log('Parsed empty or missing style attribute:', parsedEmpty);
// Expected: {} (or similar empty object if input is null/undefined/empty string)
Debug
Known issues
No known issues recorded.
Audit
Dependencies
parsimmonrequiredCore parsing logic is implemented using the Parsimmon parser combinator library.