This library convert underscored object keys to camelCase. It's helpful when you get some props or response from third party like APIs or libraries when your ESlint configured to strict camelCase properties.
import propsToCamelCase from 'props-to-camelcase';
let obj = propsToCamelCase({
user_id: 1,
user_name: 'John Doe'
});
console.log(obj);
// { userId: 1, userName: 'John Doe' }
let arr = propsToCamelCase([
{ user_id: 1 },
{ user_id: 2 }
]);
console.log(arr);
// [{ userId: 1 }, { userId: 2 }]
fetch('/users')
.then(res => res.json())
// [{ user_id: 1, user_name: 'John Doe' }]
.then(propsToCamelCase)
.then(res => console.log(res));
// [{ userId: 1, userName: 'John Doe' }]
const promise = fetch('/users').then(res => res.json());
console.log(propsToCamelCase(promise));
// [{ userId: 1, userName: 'John Doe' }]
npm start # development mode
npm build # build the library
npm test # run the tests