Skip to content

Commit

Permalink
fix: error when a field is null and flatten is used (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz authored and knownasilya committed Apr 2, 2018
1 parent e3ebed6 commit 1349a94
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
11 changes: 6 additions & 5 deletions bin/utils/TablePrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class TablePrinter {
const lines = csv.split(this.opts.eol);

const chars = {
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': ''
};
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': ''
};

if (!this._hasWritten) {
this.colWidths = this.getColumnWidths(lines[0]);
if (this.opts.header) {
Expand Down
1 change: 1 addition & 0 deletions lib/JSON2CSVBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class JSON2CSVBase {
: key;

if (typeof value !== 'object'
|| value === null
|| Array.isArray(value)
|| Object.prototype.toString.call(value.toJSON) === '[object Function]'
|| !Object.keys(value).length) {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/csv/flattenToJSON.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"hello.world","lorem.ipsum.dolor"
"good afternoon","good evening"
"hello.world","lorem.ipsum.dolor","lorem.ipsum.value"
"good afternoon","good evening",
3 changes: 2 additions & 1 deletion test/fixtures/json/flattenToJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
},
lorem: {
ipsum: {
dolor: 'good evening'
dolor: 'good evening',
value: null
}
}
}

0 comments on commit 1349a94

Please sign in to comment.