Created
February 20, 2013 00:58
-
-
Save beatak/4991759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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