Skip to content

Commit

Permalink
Merge pull request #25 from sundeepnarang/patch-1
Browse files Browse the repository at this point in the history
Add option to ignore headerRow
  • Loading branch information
nathanb committed Apr 25, 2017
2 parents d7c46ea + 900efcb commit 3e79805
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion exporter.js
Expand Up @@ -26,10 +26,11 @@ exporter.prototype.csv = function(options) {
var writtenHeader = false
this.options = options || {}
this.fieldSeparator = this.options.fieldSeparator || ',';
var ignoreHeader = this.options.ignoreHeader || false;
var self = this;

return es.through(function write(data) {
if (!writtenHeader)
if (!writtenHeader && !ignoreHeader)
{
this.emit('data', self.getHeaderRow())
writtenHeader = true
Expand Down
15 changes: 15 additions & 0 deletions test/no-header.coffee
@@ -0,0 +1,15 @@
jsoncsv = require '../index'
should = require 'should'

describe 'No Header Row', ->
it 'should not contain a header', (done) ->
items = [
{ k: 'foo' }
{ k: 'bar' }
]
jsoncsv.csvBuffered items, {
ignoreHeader: true
fields: [ { name: 'k' } ] # Label not needed
}, (err, csv) ->
csv.should.equal 'foo\r\nbar\r\n'
done()

0 comments on commit 3e79805

Please sign in to comment.