Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.14 KB

README.md

File metadata and controls

50 lines (38 loc) · 1.14 KB

PropsToCamelCase Build Status

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.

Examples

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' }]

Scripts

npm start # development mode
npm build # build the library
npm test  # run the tests