Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Underscore Mixin: toDash() #cc #underscore
_.mixin({
/* Convert CamelCase to Dashed */
toDash : function( string ){
string = string.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();});
// remove first dash
return ( string.charAt( 0 ) == '-' ) ? string.substr(1) : string;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment