csv-parse
Advanced tools
Comparing version 2.5.0 to 3.0.0
# Changelog | ||
## Version 3.0.0 | ||
Breaking changes: | ||
* columns: skip empty values when null, false or undefined | ||
Cleanup: | ||
* sync: refactor internal variables | ||
* index: use destructuring assignment for deps | ||
## Version 2.5.0 | ||
@@ -5,0 +16,0 @@ |
@@ -23,4 +23,2 @@ 'use strict'; | ||
StringDecoder = require('string_decoder').StringDecoder; | ||
// ## Usage | ||
@@ -35,2 +33,5 @@ | ||
// `parse([options], [callback])` | ||
var _require = require('string_decoder'); | ||
StringDecoder = _require.StringDecoder; | ||
module.exports = function () { | ||
@@ -306,3 +307,3 @@ var callback, called, chunks, data, err, options, parser; | ||
Parser.prototype.__push = function (line) { | ||
var call_column_udf, columns, err, field, i, j, len, lineAsColumns, record; | ||
var call_column_udf, columnName, columns, err, field, i, j, len, lineAsColumns, record; | ||
if (this._.isEnded) { | ||
@@ -369,6 +370,11 @@ return; | ||
field = line[i]; | ||
if (this.options.columns[i] === false) { | ||
columnName = this.options.columns[i]; | ||
if (columnName === void 0 || columnName === null || columnName === false) { | ||
// console.log('columnName', columnName) | ||
continue; | ||
} | ||
lineAsColumns[this.options.columns[i]] = field; | ||
if (typeof columnName !== 'string') { | ||
throw Error('Invalid column name ' + JSON.stringify(columnName)); | ||
} | ||
lineAsColumns[columnName] = field; | ||
} | ||
@@ -375,0 +381,0 @@ if (this.options.objname) { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
// Usage: `records = parse(data, [options]` | ||
// Usage: `const records = parse(data, [options]` | ||
var StringDecoder, parse; | ||
@@ -22,4 +22,4 @@ | ||
var decoder, err, parser, records; | ||
records = options.objname ? {} : []; | ||
var chunks, decoder, err, parser; | ||
chunks = options.objname ? {} : []; | ||
if (data instanceof Buffer) { | ||
@@ -30,7 +30,7 @@ decoder = new StringDecoder(); | ||
parser = new parse.Parser(options); | ||
parser.push = function (record) { | ||
parser.push = function (chunk) { | ||
if (options.objname) { | ||
return records[record[0]] = record[1]; | ||
return chunks[chunk[0]] = chunk[1]; | ||
} else { | ||
return records.push(record); | ||
return chunks.push(chunk); | ||
} | ||
@@ -52,3 +52,3 @@ }; | ||
} | ||
return records; | ||
return chunks; | ||
}; |
@@ -15,3 +15,3 @@ // Generated by CoffeeScript 2.3.1 | ||
StringDecoder = require('string_decoder').StringDecoder; | ||
({StringDecoder} = require('string_decoder')); | ||
@@ -293,3 +293,3 @@ // ## Usage | ||
Parser.prototype.__push = function(line) { | ||
var call_column_udf, columns, err, field, i, j, len, lineAsColumns, record; | ||
var call_column_udf, columnName, columns, err, field, i, j, len, lineAsColumns, record; | ||
if (this._.isEnded) { | ||
@@ -349,6 +349,11 @@ return; | ||
field = line[i]; | ||
if (this.options.columns[i] === false) { | ||
columnName = this.options.columns[i]; | ||
if (columnName === void 0 || columnName === null || columnName === false) { | ||
// console.log('columnName', columnName) | ||
continue; | ||
} | ||
lineAsColumns[this.options.columns[i]] = field; | ||
if (typeof columnName !== 'string') { | ||
throw Error(`Invalid column name ${JSON.stringify(columnName)}`); | ||
} | ||
lineAsColumns[columnName] = field; | ||
} | ||
@@ -355,0 +360,0 @@ if (this.options.objname) { |
@@ -6,3 +6,3 @@ // Generated by CoffeeScript 2.3.1 | ||
// Usage: `records = parse(data, [options]` | ||
// Usage: `const records = parse(data, [options]` | ||
var StringDecoder, parse; | ||
@@ -15,4 +15,4 @@ | ||
module.exports = function(data, options = {}) { | ||
var decoder, err, parser, records; | ||
records = options.objname ? {} : []; | ||
var chunks, decoder, err, parser; | ||
chunks = options.objname ? {} : []; | ||
if (data instanceof Buffer) { | ||
@@ -23,7 +23,7 @@ decoder = new StringDecoder(); | ||
parser = new parse.Parser(options); | ||
parser.push = function(record) { | ||
parser.push = function(chunk) { | ||
if (options.objname) { | ||
return records[record[0]] = record[1]; | ||
return chunks[chunk[0]] = chunk[1]; | ||
} else { | ||
return records.push(record); | ||
return chunks.push(chunk); | ||
} | ||
@@ -45,3 +45,3 @@ }; | ||
} | ||
return records; | ||
return chunks; | ||
}; |
{ | ||
"version": "2.5.0", | ||
"version": "3.0.0", | ||
"name": "csv-parse", | ||
@@ -4,0 +4,0 @@ "description": "CSV parsing implementing the Node.js `stream.Transform` API", |
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
74313
1784