Skip to content

Instantly share code, notes, and snippets.

@beatak
Created February 20, 2013 00:58
Show Gist options
  • Save beatak/4991759 to your computer and use it in GitHub Desktop.
Save beatak/4991759 to your computer and use it in GitHub Desktop.
function camelcase (str) {
var arr;
if (str.length === 0) {
return;
}
arr = str.split('-');
if (arr.length === 1) {
arr = str.split(' ');
}
if (arr.length === 1) {
return str;
}
return (arr.map(function (elm, i) {
if (i > 0) {
return elm[0].toUpperCase() + elm.slice(1);
} else {
return elm;
}
})).join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment