format-object-keys
Format keys in an object to be camelCase, PascalCase, or a custom format.
Install
yarn add format-object-keys
Example
// import functionconst formatObjectKeys = // provide a data structure whose// keys you want formattedconst dataStructure = FIRST_NAME: 'Kunal' LAST_NAME: 'Mandalia' LOCATION: 'London' JOB_HISTORY: DATE_FROM: 'April 2016' DATE_TO: 'Present' TITLE: 'Js developer' // define a function to format keys// here we'll camelCase key given// key has the structure <FIRSTWORD>_<SECONDWORD>...const formatter = { if typeof key === 'string' return key return key} const result = console// {// firstName: 'Kunal',// lastName: 'Mandalia',// location: 'London',// jobHistory: [// {// dateFrom: 'April 2016',// dateTo: 'Present',// title: 'Js developer'// }// ]// }
Limitations
No support for circular references yet. PRs welcome to support this feature.
License
MIT