Skip to content

Commit 08ad2b7

Browse files
committed
Fixing #10
1 parent 765c707 commit 08ad2b7

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-2-csv",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"homepage": "https://github.com/mrodrig/json-2-csv",
55
"moduleType": [
66
"node"

lib/json-2-csv.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ var convertData = function (data, keys) {
4646
_.each(keys, function (key, indx) { // For each key
4747
value = data[key]; // Set the current data that we are looking at
4848
if (keys.indexOf(key) > -1) { // If the keys contain the current key, then process the data
49-
if (typeof value === 'object' && value !== null && typeof value.length === 'undefined') { // If we have an object
50-
output.push(convertData(value, _.keys(value))); // Push the recursively generated CSV
51-
} else if (typeof value === 'object' && value !== null && typeof value.length === 'number') { // We have an array of values
49+
if (_.isArray(value)) { // We have an array of values
5250
output.push((options.DELIMITER.WRAP || '') + '[' + value.join(options.DELIMITER.ARRAY) + ']' + (options.DELIMITER.WRAP || ''));
51+
} else if (_.isDate(value)) { // If we have a date
52+
console.log(value, _.isDate(value))
53+
output.push(value.toString());
54+
} else if (_.isObject(value)) { // If we have an object
55+
output.push(convertData(value, _.keys(value))); // Push the recursively generated CSV
5356
} else {
54-
value = value == null ? '' : value;
57+
value = value == null ? '' : value.toString();
5558
output.push((options.DELIMITER.WRAP || '') + value + (options.DELIMITER.WRAP || '')); // Otherwise push the current value
5659
}
5760
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "mrodrig",
33
"name": "json-2-csv",
44
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
5-
"version": "1.0.6",
5+
"version": "1.0.7",
66
"repository": {
77
"type": "git",
88
"url": "http://github.com/mrodrig/json-2-csv.git"

0 commit comments

Comments
 (0)