Skip to content

Instantly share code, notes, and snippets.

@evolutionxbox
Created October 26, 2017 08:58
Show Gist options
  • Save evolutionxbox/bbcee7d0db7350aafb44bb0db0c1a1a5 to your computer and use it in GitHub Desktop.
Save evolutionxbox/bbcee7d0db7350aafb44bb0db0c1a1a5 to your computer and use it in GitHub Desktop.
Takes className(s) and converts it to a CSS string (although a little buggy)
/**
* "foo bar baz", "bar foo moo" -> ".foo.bar.baz .bar.foo.moo"
* @param {String...} classString
* @return {String}
*/
module.exports = function classNameToSelector(classString) {
var selector = [];
for (var i = 0, len = arguments.length; i < len; i++) {
selector.push(_classNameToSelector(arguments[i]));
}
return selector.join(' ');
};
/**
* "foo bar baz" -> ".foo.bar.baz"
* @param {String} classString
* @return {String}
*/
function _classNameToSelector(classString) {
return (' ' + classString).split(' ').join('.').trim();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment