Created
June 8, 2018 16:22
-
-
Save yosevu/adf461937379e2a41a924bb8a66ebe21 to your computer and use it in GitHub Desktop.
Kebab to Camel Case
This file contains hidden or 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
| const replaceHyphens = string => | |
| string.replace(/(-\w)/g, m => m[1].toUpperCase()); | |
| const normalizeKeys = places => { | |
| return Object.keys(places).reduce((nextPlaces, place) => { | |
| const camelCaseName = replaceHyphens(place); | |
| const currentPlace = places[place]; | |
| nextPlaces[camelCaseName] = Object.keys(currentPlace).reduce((nextPlace, prop) => { | |
| const camelCaseProp = replaceHyphens(prop); | |
| nextPlace[camelCaseProp] = currentPlace[prop]; | |
| return nextPlace; | |
| }, {}); | |
| return nextPlaces; | |
| }, {}); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment