Created
March 3, 2015 19:44
-
-
Save pseudosavant/731715198f444a3931d9 to your computer and use it in GitHub Desktop.
Camel case strings with dashes in them. E.g. 'camel-case' -> 'camelCase'
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
// Camel case strings with dashes in them. E.g. 'camel-case' -> 'camelCase' | |
function camelCase(s) { | |
function upperCaseFirst(s) { | |
return s[0].toUpperCase() + s.slice(1); | |
} | |
var separator = '-'; | |
// Return early if no additional camel casing is needed | |
if (s.indexOf(separator) === -1) { | |
return s; | |
} | |
var parts = s.split(separator); | |
return parts.map(function(v, i) { | |
if (i > 0) { | |
return upperCaseFirst(v); | |
} else { | |
return v; | |
} | |
}).join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment