Comparing version
@@ -17,3 +17,3 @@ var extended = require("./extended"), | ||
this._parsedHeaders = false; | ||
this._rowCount = 0; | ||
this._rowCount = -1; | ||
this._emitData = false; | ||
@@ -35,2 +35,3 @@ options = options || {}; | ||
this._ignoreEmpty = options.ignoreEmpty; | ||
this.__buffered = []; | ||
return this; | ||
@@ -66,3 +67,3 @@ } | ||
var ignoreEmpty = this._ignoreEmpty; | ||
if (extended.isBoolean(ignoreEmpty) && ignoreEmpty && (!line || EMPTY.test(line.join("")))) { | ||
if (extended.isBoolean(ignoreEmpty) && ignoreEmpty && (!line || EMPTY.test(line.join("")))) { | ||
return null; | ||
@@ -83,5 +84,3 @@ } | ||
_parse: function _parseLine(data, hasMoreData) { | ||
var row, | ||
emitData = this._emitData, | ||
count = 0, ret, rows, self = this; | ||
var row, count, ret, rows, self = this; | ||
try { | ||
@@ -116,8 +115,11 @@ data = this.parser(data, hasMoreData); | ||
if (row) { | ||
var dataRow = this.__handleLine(row, count); | ||
var dataRow = this.__handleLine(row, (count = ++this._rowCount)); | ||
if (dataRow) { | ||
this.emit("record", dataRow, (count = this._rowCount++)); | ||
if (emitData) { | ||
this.push(JSON.stringify(dataRow)); | ||
if (!this.paused) { | ||
this.__emitRecord(dataRow, count); | ||
} else { | ||
this.__buffered.push([dataRow, count]); | ||
} | ||
} else { | ||
count = --this._rowCount; | ||
} | ||
@@ -132,2 +134,9 @@ } | ||
__emitRecord: function (dataRow, count) { | ||
this.emit("record", dataRow, count); | ||
if (this._emitData) { | ||
this.push(JSON.stringify(dataRow)); | ||
} | ||
}, | ||
_transform: function (data, encoding, done) { | ||
@@ -151,3 +160,4 @@ var lines = this.lines; | ||
} | ||
this.emit("end", this._rowCount); | ||
//increment row count so we aren't 0 based | ||
this.emit("end", ++this._rowCount); | ||
callback(); | ||
@@ -173,2 +183,15 @@ }, | ||
this.paused = false; | ||
var buffered = this.__buffered, l = buffered.length; | ||
if (l) { | ||
var i = -1, entry; | ||
while (++i < buffered.length) { | ||
entry = buffered.shift(); | ||
this.__emitRecord(entry[0], entry[1]); | ||
//handle case where paused is called while emitting data | ||
if (this.paused) { | ||
return; | ||
} | ||
} | ||
buffered.length = 0; | ||
} | ||
if (this.__pausedDone) { | ||
@@ -175,0 +198,0 @@ var done = this.__pausedDone; |
{ | ||
"name": "fast-csv", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "CSV parser and writer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
2
-33.33%100441
-99.83%29
-23.68%546
-21.55%