Skip to content

Commit 873c2c3

Browse files
committed
Handle array structures for camelCase
1 parent 616db68 commit 873c2c3

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/normalize.js

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

15+
function isDate(attributeValue) {
16+
return Object.prototype.toString.call(attributeValue) === '[object Date]';
17+
}
18+
1519
function camelizeNestedKeys(attributeValue) {
16-
if (attributeValue === null || typeof attributeValue !== 'object' || isArray(attributeValue) || isDate(attributeValue)) {
20+
if (attributeValue === null || typeof attributeValue !== 'object' || isDate(attributeValue)) {
1721
return attributeValue;
1822
}
1923

24+
if (isArray(attributeValue)) {
25+
return attributeValue.map(camelizeNestedKeys);
26+
}
27+
2028
const copy = {};
2129

2230
keys(attributeValue).forEach((k) => {
@@ -60,10 +68,6 @@ function extractRelationships(relationships, { camelizeKeys }) {
6068
return ret;
6169
}
6270

63-
function isDate(attributeValue) {
64-
return Object.prototype.toString.call(attributeValue) === '[object Date]';
65-
}
66-
6771
function extractEntities(json, { camelizeKeys }) {
6872
const ret = {};
6973

test/normalize.spec.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,16 @@ describe('relationship meta', () => {
12131213
"id": "295"
12141214
},
12151215
"meta": {
1216-
"membership": {
1217-
"created_at": "2017-11-22",
1218-
"updated_at": "2017-11-26"
1216+
"membership": [
1217+
{
1218+
"post_id": "2620",
1219+
"question_id": "295",
1220+
"created_at": "2017-11-22",
1221+
"updated_at": "2017-11-26"
1222+
}
1223+
],
1224+
"review-status": {
1225+
"content_flags": "4"
12191226
}
12201227
}
12211228
}
@@ -1241,9 +1248,16 @@ describe('relationship meta', () => {
12411248
type: "question"
12421249
},
12431250
meta: {
1244-
membership: {
1245-
createdAt: "2017-11-22",
1246-
updatedAt: "2017-11-26"
1251+
membership: [
1252+
{
1253+
postId: "2620",
1254+
questionId: "295",
1255+
createdAt: "2017-11-22",
1256+
updatedAt: "2017-11-26"
1257+
}
1258+
],
1259+
reviewStatus: {
1260+
contentFlags: "4"
12471261
}
12481262
}
12491263
}

0 commit comments

Comments
 (0)