Last active
August 5, 2017 13:18
-
-
Save dverbovyi/b839b6d8c77affa1e0d2f21f2e748901 to your computer and use it in GitHub Desktop.
adding additional parent selector to all your css rules
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
/** | |
* @method addParentSelectorForRules - adding additional class to all your css selectors | |
* @returns {String} | |
* | |
* | |
* | |
Example: | |
Before processing | |
"header {background-color: red}" | |
After: | |
".your-class-name header {background-color: red}" | |
* | |
* | |
*/ | |
function addParentSelectorForCSSRules(css, selector) { | |
return css.replace(/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/gm, (match) => { | |
return `${selector} ${match}`; | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment