MCPcopy Index your code
hub / github.com/darkreader/darkreader / parseDeclarations

Function parseDeclarations

src/utils/css-text/parse-css.ts:97–112  ·  view source on GitHub ↗
(cssDeclarationsText: string)

Source from the content-addressed store, hash-verified

95}
96
97function parseDeclarations(cssDeclarationsText: string) {
98 const declarations: ParsedDeclaration[] = [];
99 const excludeRanges = getTokenExclusionRanges(cssDeclarationsText);
100 splitExcluding(cssDeclarationsText, ';', excludeRanges).forEach((part) => {
101 const colonIndex = part.indexOf(':');
102 if (colonIndex > 0) {
103 const importantIndex = part.indexOf('!important');
104 declarations.push({
105 property: part.substring(0, colonIndex).trim(),
106 value: part.substring(colonIndex + 1, importantIndex > 0 ? importantIndex : part.length).trim(),
107 important: importantIndex > 0,
108 });
109 }
110 });
111 return declarations;
112}
113
114export function isParsedStyleRule(rule: ParsedAtRule | ParsedStyleRule): rule is ParsedStyleRule {
115 return 'selectors' in rule;

Callers 1

parseCSSFunction · 0.85

Calls 2

splitExcludingFunction · 0.90
getTokenExclusionRangesFunction · 0.85

Tested by

no test coverage detected