Skip to content

Instantly share code, notes, and snippets.

@tracend
Last active December 16, 2015 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracend/5419653 to your computer and use it in GitHub Desktop.
Save tracend/5419653 to your computer and use it in GitHub Desktop.
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