Skip to content

Instantly share code, notes, and snippets.

@shuhei
Created December 2, 2012 04:51
Show Gist options
  • Save shuhei/4187012 to your computer and use it in GitHub Desktop.
Save shuhei/4187012 to your computer and use it in GitHub Desktop.
Hyphenated lower case to camel case
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.substring(1);
}
function toCamelCase(hyphenated, isLower) {
var components = hyphenated.split('-');
for (var i = 0; i < components.length; i++) {
if (!(isLower && i === 0)) {
components[i] = capitalize(components[i]);
}
}
return components.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment