Skip to content

Instantly share code, notes, and snippets.

@akirattii
Created June 21, 2016 11:39
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 akirattii/460b6c507d9c5b6f51caea985a12da27 to your computer and use it in GitHub Desktop.
Save akirattii/460b6c507d9c5b6f51caea985a12da27 to your computer and use it in GitHub Desktop.
CamelCase <-> HyphenCase converter
// 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