Skip to content

Instantly share code, notes, and snippets.



Last active Oct 31, 2016
What would you like to do?
Clean CSS identifier from string
// In a perfect world, you'd never have to do this. Wish I lived in a perfect world.
* Convert a string to a usable class name
* @param {string} stringToConvert String of text
* @return {string} Usable class name
function convertStringToClassName(stringToConvert) {
if (typeof stringToConvert === 'string') {
return stringToConvert.trim().replace(/[\s-_]+/g, '-').replace(/[^\w-]|^-|-$/g, '').replace(/-+(?=-)/, '').toLowerCase();

This comment has been minimized.

Copy link
Owner Author

@wesruv wesruv commented Oct 31, 2016

Updated with @m4olivei's feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.