Skip to content

Commit 7de592e

Browse files
committed
1 parent 21dcc1a commit 7de592e

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
###v. 0.4.5 (23 Oct 2017)
2+
While processing nested objects, we should handle dates accordingly (https://github.com/yury-dymov/json-api-normalizer/issues/23)
3+
14
###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)
5+
While processing nested objects, we shouldn't change array attributes to object (https://github.com/yury-dymov/json-api-normalizer/issues/22)
36

47
###v. 0.4.3 (20 Oct 2017)
58
Nested attribute keys are also camelized now (https://github.com/yury-dymov/json-api-normalizer/issues/21)

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.4",
3+
"version": "0.4.5",
44
"description": "JSON API response normalizer",
55
"main": "dist/bundle.js",
66
"scripts": {

src/normalize.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ function extractRelationships(relationships, { camelizeKeys }) {
4242
return ret;
4343
}
4444

45+
function isDate(attributeValue) {
46+
return Object.prototype.toString.call(attributeValue) === '[object Date]';
47+
}
48+
4549
function camelizeNestedKeys(attributeValue) {
46-
if (attributeValue === null || typeof attributeValue !== 'object' || isArray(attributeValue)) {
50+
if (attributeValue === null || typeof attributeValue !== 'object' || isArray(attributeValue) || isDate(attributeValue)) {
4751
return attributeValue;
4852
}
4953

test/normalize.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,33 @@ describe('data is normalized', () => {
153153

154154
expect(isEqual(normalize(input), camelizedOutput)).to.be.true;
155155
});
156+
157+
it('dates should not be affected by camilization', () => {
158+
const date = new Date();
159+
160+
const obj = {
161+
data: {
162+
id: 1,
163+
type: 'projects',
164+
attributes: {
165+
'started-at': date
166+
}
167+
}
168+
};
169+
170+
const output = {
171+
projects: {
172+
"1": {
173+
id: 1,
174+
attributes: {
175+
startedAt: date
176+
}
177+
}
178+
}
179+
};
180+
181+
expect(isEqual(normalize(obj), output)).to.be.true;
182+
});
156183
});
157184

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

0 commit comments

Comments
 (0)