Last active
January 19, 2019 21:41
-
-
Save tomhodgins/19150f82943ff0243cb91a53e8e10f47 to your computer and use it in GitHub Desktop.
Process CSSRule objects with a callback function when given a CSSStyleSheet object and function as inputs
This file contains 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
export default function(stylesheet, callback) { | |
const readRules = list => Array.from(list.cssRules).forEach(rule => { | |
callback(rule) | |
if (rule.cssRules !== undefined) { | |
readRules(rule) | |
} | |
}) | |
if ( | |
[stylesheet, stylesheet.cssRules, callback].every(thing => thing !== undefined) | |
&& callback.constructor.name === 'Function' | |
) { | |
readRules(stylesheet) | |
return stylesheet | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment