Created
August 15, 2016 22:25
-
-
Save klzns/ea7e7886e5cfa6272b4f7483ebb2a64f to your computer and use it in GitHub Desktop.
Transform camelCase to ACTION_NAMES
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 transformToActionNames(actions) { | |
return _.map(actions, (action) => { | |
let newActionName = '' | |
for (var index = 0; index < action.length; index++) { | |
var char = action[index] | |
if (index === 0) { | |
newActionName += char.toUpperCase() | |
continue | |
} | |
if (char == char.toUpperCase()) { | |
newActionName += '_' + char | |
continue | |
} | |
newActionName += char.toUpperCase() | |
} | |
return newActionName | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment