Created
October 4, 2020 15:54
-
-
Save UpperCod/31cd0f2611de3559713ea15b4fa29a06 to your computer and use it in GitHub Desktop.
capture the css blocks, great to use with sheet.insertRule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const add = (list: string[]) => (rule: string) => list.push(rule) && ""; | |
function parse(css: string) { | |
const rules = []; | |
const atRules = []; | |
css | |
.replace(/\s+/g, " ") | |
.replace(/@([^{]+)\{(.*?}) *}/g, add(atRules)) | |
.replace(/([^}{;]*){([^}{]+)}/g, add(rules)); | |
return [...rules, ...atRules]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment