Skip to content

Commit 21dcc1a

Browse files
committed
1 parent c6e921c commit 21dcc1a

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
###v. 0.4.4 (23 Oct 2017)
2+
While we process nested objects, we shouldn't change array attributes to object (https://github.com/yury-dymov/json-api-normalizer/issues/22)
3+
14
###v. 0.4.3 (20 Oct 2017)
25
Nested attribute keys are also camelized now (https://github.com/yury-dymov/json-api-normalizer/issues/21)
36

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-api-normalizer",
3-
"version": "0.4.3",
3+
"version": "0.4.4",
44
"description": "JSON API response normalizer",
55
"main": "dist/bundle.js",
66
"scripts": {

src/normalize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function extractRelationships(relationships, { camelizeKeys }) {
4343
}
4444

4545
function camelizeNestedKeys(attributeValue) {
46-
if (attributeValue === null || typeof attributeValue !== 'object') {
46+
if (attributeValue === null || typeof attributeValue !== 'object' || isArray(attributeValue)) {
4747
return attributeValue;
4848
}
4949

test/normalize.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,31 @@ describe('data is normalized', () => {
128128

129129
expect(isEqual(normalize(input), camelizedOutput)).to.be.true;
130130
});
131+
132+
it('arrays are still array after camelization', () => {
133+
const input = {
134+
data: [{
135+
type: 'post',
136+
id: 1,
137+
attributes: {
138+
key_is_camelized: ['a', 'b']
139+
}
140+
}]
141+
};
142+
143+
const camelizedOutput = {
144+
post: {
145+
"1": {
146+
id: 1,
147+
attributes: {
148+
keyIsCamelized: ['a', 'b']
149+
}
150+
}
151+
}
152+
};
153+
154+
expect(isEqual(normalize(input), camelizedOutput)).to.be.true;
155+
});
131156
});
132157

133158
describe('included is normalized', () => {

0 commit comments

Comments
 (0)