Last active
December 16, 2015 10:19
-
-
Save tracend/5419653 to your computer and use it in GitHub Desktop.
Underscore Mixin: toDash() #cc #underscore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.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