Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.