Skip to content

Instantly share code, notes, and snippets.

@IgorHalfeld
Created September 19, 2020 10:28
Show Gist options
  • Save IgorHalfeld/dd3944dd1a8a710bf0ae72ef1a27ac07 to your computer and use it in GitHub Desktop.
Save IgorHalfeld/dd3944dd1a8a710bf0ae72ef1a27ac07 to your computer and use it in GitHub Desktop.
export const kebabToCamel = obj => Object.keys(obj).reduce((acc, cur) => {
return {
...acc,
[camelize(cur)]: buildValue(obj[cur])
}
}, {})
function camelize (property) {
const s = property.split('_')
const capital = s.map((item, index) => {
if (index === 0) {
return item
}
return item.charAt(0).toUpperCase() + item.slice(1).toLowerCase()
})
return capital.join('')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment