Skip to content

Instantly share code, notes, and snippets.

@marr
Created May 29, 2018 21:44
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 marr/a2ce474ff5f201281fabfdbb891ebd8a to your computer and use it in GitHub Desktop.
Save marr/a2ce474ff5f201281fabfdbb891ebd8a to your computer and use it in GitHub Desktop.
import transform from 'transform-keys'
// https://github.com/bjoerge/transform-keys#custom-key-transformers
export function camelify(obj) {
return transform(obj, (key) => {
return key.replace(/_([a-z])/ig, (_, $1) => {
return $1.toUpperCase()
})
})
}
// https://github.com/bjoerge/transform-keys#custom-key-transformers
export function snakeify(obj) {
return transform(obj, (key) => {
return key.replace(/([A-Z])/g, (_, $1) => {
return '_' + $1.toLowerCase()
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment