Skip to content

Commit

Permalink
update v0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
caio-ribeiro-pereira committed Sep 8, 2020
1 parent f193f31 commit d099a5e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.0.6
+ Improvements: fix deep keys transformation [xingyeqishi](https://github.com/caio-ribeiro-pereira/field-normalizer/pull/3)

## 0.0.5
+ Feature: export transform factory function
+ Feature: export constant of allowed function
Expand Down
3 changes: 2 additions & 1 deletion lib/fnz.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const transform = (object, functionName) => {
return keys.reduce((normalized, key) => {
const native = NATIVE_FUNCTIONS.includes(functionName);
const transformedKey = native ? key[functionName]() : changeCase[functionName](key);
normalized[transformedKey] = isValidObject(object[key]) ? transform(object[key], functionName) : object[key];
const isValidKey = isValidObject(object[key]);
normalized[transformedKey] = isValidKey ? transform(object[key], functionName) : object[key];
return normalized;
}, {});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "field-normalizer",
"description": "A tiny lib for object field's normalization",
"version": "0.0.5",
"version": "0.0.6",
"main": "index.js",
"license": "MIT",
"author": "Caio Ribeiro Pereira <caio.ribeiro.pereira@gmail.com>",
Expand Down
16 changes: 8 additions & 8 deletions test/fnz.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ const camelCaseObj = {
contactEmail: 'john.connor@sky.net',
phoneNumber: '+05533334444',
userSkill: {
useJavascript: true
}
useJavascript: true,
},
};

const pascalCaseObj = {
FullName: 'John Connor',
ContactEmail: 'john.connor@sky.net',
PhoneNumber: '+05533334444',
UserSkill: {
UseJavascript: true
}
UseJavascript: true,
},
};

const constantCaseObj = {
FULL_NAME: 'John Connor',
CONTACT_EMAIL: 'john.connor@sky.net',
PHONE_NUMBER: '+05533334444',
User_Skill: {
Use_Javascript: true
}
Use_Javascript: true,
},
};

const snakeCaseObj = {
full_name: 'John Connor',
contact_email: 'john.connor@sky.net',
phone_number: '+05533334444',
user_skill: {
use_javascript: true
}
use_javascript: true,
},
};

const { FUNCTIONS } = fnz;
Expand Down

0 comments on commit d099a5e

Please sign in to comment.