Skip to content

Instantly share code, notes, and snippets.

@xeaone
Last active August 16, 2016 16:47
Show Gist options
  • Save xeaone/fb0213c43e1811d28bfaf116c56baea3 to your computer and use it in GitHub Desktop.
Save xeaone/fb0213c43e1811d28bfaf116c56baea3 to your computer and use it in GitHub Desktop.
function toCamelCase (string) {
var nextIndex = string.search('-') + 1;
var nextLetter = string.charAt(nextIndex).toString();
var r = '-' + nextLetter;
var n = nextLetter.toUpperCase();
return string.replace(r, n);
}
function fromCamelCase (string) {
var firstChar = string.charAt(0).toString();
string = string.replace(firstChar, firstChar.toLowerCase());
// replace upper case with hypeh and lower cased char
for (var i = 0; i < string.length; i++) {
var char = string[i];
if (isUpperCase(char)) string = string.replace(char, '-' + char.toLowerCase()) ;
}
return string;
}
function isUpperCase (char) {
return (char >= 'A') && (char <= 'Z');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment