From daeae700111a6123c348815a9bccc5b8b64ab1a0 Mon Sep 17 00:00:00 2001 From: Nathan Bridgewater Date: Sun, 26 Mar 2017 12:11:32 -0500 Subject: [PATCH] updating dependencies, fixing 23; also fixes undefined columns --- .travis.yml | 4 ++-- exporter.js | 2 +- package.json | 14 +++++++------- test/issue-23.coffee | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 test/issue-23.coffee diff --git a/.travis.yml b/.travis.yml index e0792e5..774a377 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: -- '5' -- '4' +- '7' +- '6' - '0.10' script: "mocha" cache: diff --git a/exporter.js b/exporter.js index 332206e..6864537 100644 --- a/exporter.js +++ b/exporter.js @@ -49,7 +49,7 @@ exporter.prototype.prepValue = function(arg, forceQuoted) { exporter.prototype.getHeaderRow = function() { var self = this var header = _.reduce(self.options.fields, function(line, field) { - var label = field.label || field.field + var label = field.label || field.name if (line === 'START') { line = ''; } else { diff --git a/package.json b/package.json index cf42229..b9ff6cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "json-csv", - "version": "1.3.0", + "version": "1.4.0", "description": "Export a richly structured, JSON array to CSV", "homepage": "https://github.com/IWSLLC/json-csv", "author": "Nathan Bridgewater (http://iws.io/)", @@ -18,9 +18,9 @@ "node": ">=0.10" }, "devDependencies": { - "coffee-script": "^1.10.0", - "mocha": "^2.4.5", - "should": "^8.3.0" + "coffee-script": "^1.12.4", + "mocha": "^3.2.0", + "should": "^11.2.1" }, "bugs": { "url": "https://github.com/IWSLLC/json-csv/issues" @@ -29,9 +29,9 @@ "test": "test" }, "dependencies": { - "concat-stream": "^1.5.1", - "event-stream": "^3.3.2", - "lodash": "^4.7.0" + "concat-stream": "^1.6.0", + "event-stream": "^3.3.4", + "lodash": "^4.17.4" }, "scripts": { "test": "mocha" diff --git a/test/issue-23.coffee b/test/issue-23.coffee new file mode 100644 index 0000000..e7ac4c2 --- /dev/null +++ b/test/issue-23.coffee @@ -0,0 +1,33 @@ +jsoncsv = require '../index' +should = require "should" + +describe "Issue 23", -> + describe "When excluding label definitions", -> + before (done) -> + @items = [{a: "first", b: "second"}, {a: "third", b:"fourth"}, {a: "fifth", b: "sixth"}] + jsoncsv.csvBuffered @items, { + fields: [ + {name: "a", label: "a"} + {name: "b"} # this is breaking (before fix) + ]}, (err, csv) => + @csv = csv + @err = err + done() + + it "should export a and b", -> @csv.should.equal "a,b\r\nfirst,second\r\nthird,fourth\r\nfifth,sixth\r\n" + + #also this issue came up (because of the first one) + describe "When exporting a column that resolves undefined in the data set", -> + before (done) -> + @items = [{a: "first", b: "second"}, {a: "third", b:"fourth"}, {a: "fifth", b: "sixth"}] + jsoncsv.csvBuffered @items, { + fields: [ + {name: "a"} + {name: "b"} + {name: "c"} #breaking before fix + ]}, (err, csv) => + @csv = csv + @err = err + done() + + it "should export a, b, and c", -> @csv.should.equal "a,b,c\r\nfirst,second,\r\nthird,fourth,\r\nfifth,sixth,\r\n"