Skip to content

Instantly share code, notes, and snippets.

@ccarrasc
Created July 24, 2018 18:35
Show Gist options
  • Save ccarrasc/1e70fc2dd56767ff7350e506d98500e1 to your computer and use it in GitHub Desktop.
Save ccarrasc/1e70fc2dd56767ff7350e506d98500e1 to your computer and use it in GitHub Desktop.
Convert PascalCased props to camelCase (not really tested)
const toCamelCaseProps = (obj: any) => {
return Object.keys(obj).reduce((renamed, key) => {
let value = obj[key];
if (typeof value === 'object' && value) {
value = toCamelCaseProps(value);
}
const camelCasedKey = key.charAt(0).toLowerCase() + key.slice(1);
renamed[camelCasedKey] = value;
return renamed;
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment