Skip to content

Add class and/or ID to all elements in a stylesheet.

License

Notifications You must be signed in to change notification settings

tabeth/css-prefixer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

#css-prefixer Add class and/or ID to all elements in a stylesheet.

It's dead simple. Use it online, or copy the code below and use it yourself:

/* Prefixes a given CSS string.
 *
 * @param {String} cssString - the CSS which has rules to be prefixed
 * @param {String} prefixName - the string to be used in prefixing
 * @param {String} delimiter - the delimiter to be used
 * @returns {String} original cssString prefixed by prefixName. Comments are removed.
 */
function prefixCSSRule(cssString, prefixName, delimiter = ' ') {
  var uncommentedCSS = cssString.replace(/(\/\*[^]*?\*\/)/g, '');
  return uncommentedCSS.replace(/([,|\}][\s$]*)((\/\/.*[\s$]+|.*\/\*.*\*\/[\s$]*|@media.*\{[\s$]*|)*)([\.#]?-?[_a-zA-Z]+[_a-zA-Z0-9-]*)/g, '$1$2' + prefixName + delimiter + '$4');
}

#acknowledgements RustyTheBoyRobot on stackoverflow

About

Add class and/or ID to all elements in a stylesheet.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published