Created
June 21, 2016 11:39
-
-
Save akirattii/460b6c507d9c5b6f51caea985a12da27 to your computer and use it in GitHub Desktop.
CamelCase <-> HyphenCase converter
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
// camelCase -> hyphenCase | |
function camelToHyphenCase: function(str) { | |
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | |
} | |
// hyphenCase -> camelCase | |
function hyphenToCamelCase(str) { | |
return str.replace(/-([a-z])/g, function(g) { | |
return g[1].toUpperCase(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment