props-to-camelcase

0.1.6 • Public • Published

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 

Readme

Keywords

none

Package Sidebar

Install

npm i props-to-camelcase

Weekly Downloads

2

Version

0.1.6

License

MIT

Unpacked Size

225 kB

Total Files

7

Last publish

Collaborators

  • nurislamov