Skip to content

Instantly share code, notes, and snippets.

@aarongustafson
Created December 6, 2009 00:58
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 aarongustafson/249955 to your computer and use it in GitHub Desktop.
Save aarongustafson/249955 to your computer and use it in GitHub Desktop.
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