csv-parser
Advanced tools
Comparing version 1.4.6 to 1.5.0
13
index.js
@@ -8,3 +8,2 @@ var stream = require('stream') | ||
var comma = new Buffer(',')[0] | ||
var lf = new Buffer('\n')[0] | ||
var cr = new Buffer('\r')[0] | ||
@@ -19,2 +18,10 @@ | ||
this.separator = opts.separator ? new Buffer(opts.separator)[0] : comma | ||
if(opts.newline) { | ||
this.newline = new Buffer(opts.newline)[0] | ||
this.customNewline = true | ||
} else { | ||
this.newline = new Buffer('\n')[0] | ||
this.customNewline = false | ||
} | ||
this.headers = opts.headers || null | ||
@@ -53,3 +60,3 @@ | ||
if (!this._quoting && buf[i] === lf) { | ||
if (!this._quoting && buf[i] === this.newline) { | ||
this._online(buf, this._prevEnd, i+1) | ||
@@ -83,3 +90,3 @@ this._prevEnd = i+1 | ||
end -- // trim newline | ||
if (buf.length && buf[end-1] === cr) end-- | ||
if (!this.customNewline && buf.length && buf[end-1] === cr) end-- | ||
@@ -86,0 +93,0 @@ var comma = this.separator |
{ | ||
"name": "csv-parser", | ||
"version": "1.4.6", | ||
"version": "1.5.0", | ||
"description": "Streaming csv parser inspired by binary-csv that aims to be faster than everyone else", | ||
@@ -5,0 +5,0 @@ "repository": "mafintosh/csv-parser", |
@@ -37,3 +37,4 @@ # csv-parser | ||
raw: false, // do not decode to utf-8 strings | ||
separator: ',' // specify optional cell separator | ||
separator: ',', // specify optional cell separator | ||
newline: '\n' // specify a newline character | ||
}) | ||
@@ -40,0 +41,0 @@ ``` |
@@ -220,2 +220,14 @@ var test = require('tape') | ||
test('custom newline', function(t) { | ||
collect('custom-newlines.csv', {newline: 'X'},verify) | ||
function verify(err, lines) { | ||
t.false(err, 'no err') | ||
t.same(lines[0], {a:'1', b:'2', c:'3'}, 'first row') | ||
t.same(lines[1], {a:'X-Men', b:'5', c:'6'}, 'second row') | ||
t.same(lines[2], {a:'7', b:'8', c:'9'}, 'third row') | ||
t.equal(lines.length, 3, '3 rows') | ||
t.end() | ||
} | ||
}) | ||
// helpers | ||
@@ -222,0 +234,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15903
22
407
60