Skip to content

Instantly share code, notes, and snippets.

@klzns
Created August 15, 2016 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klzns/ea7e7886e5cfa6272b4f7483ebb2a64f to your computer and use it in GitHub Desktop.
Save klzns/ea7e7886e5cfa6272b4f7483ebb2a64f to your computer and use it in GitHub Desktop.
Transform camelCase to ACTION_NAMES
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