Last active
March 22, 2016 07:16
-
-
Save swapnilmishra/b59cfe77829a0789111a to your computer and use it in GitHub Desktop.
Function to convert underscored names to camelCased
This file contains 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 underscoreToCamelCase(param){ | |
var paramArray, firstLetter,camelCased=''; | |
try{ | |
paramArray = param ? param.split('_') : []; | |
// case where there is no underscore | |
if(paramArray.length < 2){ | |
return (paramArray.length>0 ? paramArray[0].toLowerCase() : param); | |
} | |
for (var i = 1; i < paramArray.length; i++) { | |
firstLetter = paramArray[i].charAt(0); | |
firstLetter = firstLetter.toUpperCase(); | |
camelCased += firstLetter + paramArray[i].substr(1,paramArray[i].length-1); | |
} | |
return paramArray[0].toLowerCase()+camelCased; | |
} | |
catch(e){ | |
return param; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment