Skip to content

Commit

Permalink
Refactoring camelCaseKeys()
Browse files Browse the repository at this point in the history
  • Loading branch information
segayuu committed Nov 15, 2018
1 parent 40270ac commit cbd6a18
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/camel_case_keys.js
Expand Up @@ -29,18 +29,17 @@ function camelCaseKeys(obj) {
if (typeof obj !== 'object') throw new TypeError('obj must be an object!');

const keys = Object.keys(obj);
const { length } = keys;
const result = {};

for (let i = 0, len = keys.length; i < len; i++) {
const key = keys[i];
const value = obj[key];
const newKey = toCamelCase(key);
for (let i = 0; i < length; i++) {
const oldKey = keys[i];
const newKey = toCamelCase(oldKey);

if (newKey === key) {
result[key] = value;
} else {
result[newKey] = value;
Object.defineProperty(result, key, {
result[newKey] = obj[oldKey];

if (newKey !== oldKey) {
Object.defineProperty(result, oldKey, {
get: getter(newKey),
set: setter(newKey),
configurable: true,
Expand Down

0 comments on commit cbd6a18

Please sign in to comment.