JSFiddle - React, Tailwind, and code Playground
by Scott Kaye
JavaScript
console.clear();
let sheet = `
* {
position: sticky;
background: #0f0;
}
span > i.fa {
color: red;
}
`;
let rules = [];
let matcher = /(.+?)\{([\s\S]+?)\}/g;
let normalize = s => s.replace(/[\r\n\t\s]/g, "");
let match;
while(match = matcher.exec(sheet)) {
let selector = normalize(match[1]);
let css = normalize(match[0]);
let style = {};
let subMatch;
let subMatcher = /([a-z]+)\:(.+?);/g;
while (subMatch = subMatcher.exec(css)) {
style[subMatch[1]] = subMatch[2];
}
rules.push({
selectorText: selector,
cssText: css,
style: style
});
}
console.log(rules);