Skip to content

Instantly share code, notes, and snippets.

@wesruv wesruv/function.js
Last active Oct 31, 2016

Embed
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();
}
};
@wesruv

This comment has been minimized.

Copy link
Owner Author

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.