Skip to content

Instantly share code, notes, and snippets.

@yosevu
Created June 8, 2018 16:22
Show Gist options
  • Select an option

  • Save yosevu/adf461937379e2a41a924bb8a66ebe21 to your computer and use it in GitHub Desktop.

Select an option

Save yosevu/adf461937379e2a41a924bb8a66ebe21 to your computer and use it in GitHub Desktop.
Kebab to Camel Case
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