Socket
Socket
Sign inDemoInstall

csv-parse

Package Overview
Dependencies
1
Maintainers
1
Versions
141
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.7.0 to 4.8.0

9

CHANGELOG.md

@@ -6,3 +6,5 @@

* skip_lines_with_empty_values: rename to skip_records_with_empty_values
* skip_lines_with_error: rename to skip_records_with_error
* relax: rename to relax_quotes_when_unquoted
* max_comment_size: new option

@@ -12,2 +14,9 @@ * promise: new API module

## Version 4.8.0
* relax_column_count: new less and more options
* columns: skip empty records before detecting headers
* errors: rename CSV_INCONSISTENT_RECORD_LENGTH
* errors: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH
## Version 4.7.0

@@ -14,0 +23,0 @@

40

lib/es5/index.js

@@ -304,2 +304,16 @@ "use strict";

throw new Error("Invalid Option: relax_column_count must be a boolean, got ".concat(JSON.stringify(options.relax_column_count)));
}
if (typeof options.relax_column_count_less === 'boolean') {// Great, nothing to do
} else if (options.relax_column_count_less === undefined || options.relax_column_count_less === null) {
options.relax_column_count_less = false;
} else {
throw new Error("Invalid Option: relax_column_count_less must be a boolean, got ".concat(JSON.stringify(options.relax_column_count_less)));
}
if (typeof options.relax_column_count_more === 'boolean') {// Great, nothing to do
} else if (options.relax_column_count_more === undefined || options.relax_column_count_more === null) {
options.relax_column_count_more = false;
} else {
throw new Error("Invalid Option: relax_column_count_more must be a boolean, got ".concat(JSON.stringify(options.relax_column_count_more)));
} // Normalize option `skip_empty_lines`

@@ -778,2 +792,4 @@

relax_column_count = _this$options2.relax_column_count,
relax_column_count_less = _this$options2.relax_column_count_less,
relax_column_count_more = _this$options2.relax_column_count_more,
raw = _this$options2.raw,

@@ -793,2 +809,8 @@ skip_lines_with_empty_values = _this$options2.skip_lines_with_empty_values;

if (columns === true) {
if (isRecordEmpty(record)) {
this.__resetRow();
return;
}
return this.__firstLineToColumns(record);

@@ -802,7 +824,7 @@ }

if (recordLength !== this.state.expectedRecordLength) {
if (relax_column_count === true) {
if (relax_column_count === true || relax_column_count_less === true && recordLength < this.state.expectedRecordLength || relax_column_count_more === true && recordLength > this.state.expectedRecordLength) {
this.info.invalid_field_length++;
} else {
if (columns === false) {
var err = this.__error(new CsvError('CSV_INVALID_RECORD_LENGTH_DONT_PREVIOUS_RECORDS', ['Invalid Record Length:', "expect ".concat(this.state.expectedRecordLength, ","), "got ".concat(recordLength, " on line ").concat(this.info.lines)], this.__context(), {
var err = this.__error(new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', ['Invalid Record Length:', "expect ".concat(this.state.expectedRecordLength, ","), "got ".concat(recordLength, " on line ").concat(this.info.lines)], this.__context(), {
record: record

@@ -813,3 +835,5 @@ }));

} else {
var _err5 = this.__error(new CsvError('CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS', ['Invalid Record Length:', "header length is ".concat(columns.length, ","), "got ".concat(recordLength, " on line ").concat(this.info.lines)], this.__context(), {
var _err5 = this.__error( // CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', ['Invalid Record Length:', "columns length is ".concat(columns.length, ","), // rename columns
"got ".concat(recordLength, " on line ").concat(this.info.lines)], this.__context(), {
record: record

@@ -824,5 +848,3 @@ }));

if (skip_lines_with_empty_values === true) {
if (record.every(function (field) {
return field == null || field.toString && field.toString().trim() === '';
})) {
if (isRecordEmpty(record)) {
this.__resetRow();

@@ -1268,2 +1290,8 @@

var isRecordEmpty = function isRecordEmpty(record) {
return record.every(function (field) {
return field == null || field.toString && field.toString().trim() === '';
});
};
var normalizeColumnsArray = function normalizeColumnsArray(columns) {

@@ -1270,0 +1298,0 @@ var normalizedColumns = [];

@@ -248,2 +248,16 @@

}
if(typeof options.relax_column_count_less === 'boolean'){
// Great, nothing to do
}else if(options.relax_column_count_less === undefined || options.relax_column_count_less === null){
options.relax_column_count_less = false
}else{
throw new Error(`Invalid Option: relax_column_count_less must be a boolean, got ${JSON.stringify(options.relax_column_count_less)}`)
}
if(typeof options.relax_column_count_more === 'boolean'){
// Great, nothing to do
}else if(options.relax_column_count_more === undefined || options.relax_column_count_more === null){
options.relax_column_count_more = false
}else{
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`)
}
// Normalize option `skip_empty_lines`

@@ -651,3 +665,3 @@ if(typeof options.skip_empty_lines === 'boolean'){

__onRow(){
const {columns, info, from, relax_column_count, raw, skip_lines_with_empty_values} = this.options
const {columns, info, from, relax_column_count, relax_column_count_less, relax_column_count_more, raw, skip_lines_with_empty_values} = this.options
const {enabled, record} = this.state

@@ -660,2 +674,6 @@ if(enabled === false){

if(columns === true){
if(isRecordEmpty(record)){
this.__resetRow()
return
}
return this.__firstLineToColumns(record)

@@ -667,3 +685,5 @@ }

if(recordLength !== this.state.expectedRecordLength){
if(relax_column_count === true){
if(relax_column_count === true ||
(relax_column_count_less === true && recordLength < this.state.expectedRecordLength) ||
(relax_column_count_more === true && recordLength > this.state.expectedRecordLength) ){
this.info.invalid_field_length++

@@ -673,3 +693,3 @@ }else{

const err = this.__error(
new CsvError('CSV_INVALID_RECORD_LENGTH_DONT_PREVIOUS_RECORDS', [
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
'Invalid Record Length:',

@@ -685,5 +705,6 @@ `expect ${this.state.expectedRecordLength},`,

const err = this.__error(
new CsvError('CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS', [
// CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
'Invalid Record Length:',
`header length is ${columns.length},`,
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,

@@ -699,3 +720,3 @@ ], this.__context(), {

if(skip_lines_with_empty_values === true){
if(record.every( (field) => field == null || field.toString && field.toString().trim() === '' )){
if(isRecordEmpty(record)){
this.__resetRow()

@@ -1041,2 +1062,6 @@ return

const isRecordEmpty = function(record){
return record.every( (field) => field == null || field.toString && field.toString().trim() === '' )
}
const normalizeColumnsArray = function(columns){

@@ -1043,0 +1068,0 @@ const normalizedColumns = [];

2

package.json
{
"version": "4.7.0",
"version": "4.8.0",
"name": "csv-parse",

@@ -4,0 +4,0 @@ "description": "CSV parsing implementing the Node.js `stream.Transform` API",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc