Created
May 29, 2018 21:44
-
-
Save marr/a2ce474ff5f201281fabfdbb891ebd8a to your computer and use it in GitHub Desktop.
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
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