Skip to content

Instantly share code, notes, and snippets.

@swapnilmishra
Last active March 22, 2016 07:16
Show Gist options
  • Save swapnilmishra/b59cfe77829a0789111a to your computer and use it in GitHub Desktop.
Save swapnilmishra/b59cfe77829a0789111a to your computer and use it in GitHub Desktop.
Function to convert underscored names to camelCased
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