Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function camelize( str )
{
var
HYPHEN = '-',
bits = str.split(HYPHEN),
length = bits.length,
i = 1,
new_str;
if ( length == 1 ) { return bits[0]; }
if ( str.charAt(0) == HYPHEN ) {
new_str = bits[0].charAt(0).toUpperCase() + bits[0].substring(1);
} else {
new_str = bits[0];
}
while ( i < length ) {
new_str += bits[i].charAt(0).toUpperCase() + bits[i].substring(1);
i++;
}
return new_str;
}
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.