Skip to content

Commit 616db68

Browse files
committed
Perform camelCase on meta properties
1 parent 4e6fd72 commit 616db68

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/normalize.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ function wrap(json) {
1212
return [json];
1313
}
1414

15+
function camelizeNestedKeys(attributeValue) {
16+
if (attributeValue === null || typeof attributeValue !== 'object' || isArray(attributeValue) || isDate(attributeValue)) {
17+
return attributeValue;
18+
}
19+
20+
const copy = {};
21+
22+
keys(attributeValue).forEach((k) => {
23+
copy[camelCase(k)] = camelizeNestedKeys(attributeValue[k]);
24+
});
25+
26+
return copy;
27+
}
28+
1529
function extractRelationships(relationships, { camelizeKeys }) {
1630
const ret = {};
1731
keys(relationships).forEach((key) => {
@@ -35,7 +49,7 @@ function extractRelationships(relationships, { camelizeKeys }) {
3549
}
3650

3751
if (typeof relationship.meta !== 'undefined') {
38-
ret[name].meta = relationship.meta;
52+
ret[name].meta = camelizeNestedKeys(relationship.meta);
3953
}
4054
}
4155

@@ -50,20 +64,6 @@ function isDate(attributeValue) {
5064
return Object.prototype.toString.call(attributeValue) === '[object Date]';
5165
}
5266

53-
function camelizeNestedKeys(attributeValue) {
54-
if (attributeValue === null || typeof attributeValue !== 'object' || isArray(attributeValue) || isDate(attributeValue)) {
55-
return attributeValue;
56-
}
57-
58-
const copy = {};
59-
60-
keys(attributeValue).forEach((k) => {
61-
copy[camelCase(k)] = camelizeNestedKeys(attributeValue[k]);
62-
});
63-
64-
return copy;
65-
}
66-
6767
function extractEntities(json, { camelizeKeys }) {
6868
const ret = {};
6969

test/normalize.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,8 @@ describe('relationship meta', () => {
12141214
},
12151215
"meta": {
12161216
"membership": {
1217-
"createdAt": "2017-11-22",
1218-
"updatedAt": "2017-11-26"
1217+
"created_at": "2017-11-22",
1218+
"updated_at": "2017-11-26"
12191219
}
12201220
}
12211221
}

0 commit comments

Comments
 (0)