Socket
Socket
Sign inDemoInstall

csv-parse

Package Overview
Dependencies
0
Maintainers
1
Versions
141
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.7 to 1.1.8

213

lib/index.js

@@ -79,3 +79,3 @@ // Generated by CoffeeScript 1.10.0

Parser = function(options) {
var base, base1, base10, base11, base12, base13, base14, base15, base16, base2, base3, base4, base5, base6, base7, base8, base9, k, v;
var base, base1, base10, base11, base12, base13, base14, base15, base2, base3, base4, base5, base6, base7, base8, base9, k, v;
if (options == null) {

@@ -91,52 +91,60 @@ options = {};

stream.Transform.call(this, this.options);
if ((base = this.options).rowDelimiter == null) {
base.rowDelimiter = null;
if (this.options.rowDelimiter != null) {
if (typeof this.options.rowDelimiter === "string") {
this.options.rowDelimiter = [this.options.rowDelimiter];
this.receivedRowDelimiterAsString = true;
} else if (this.options.rowDelimiter.constructor === Array) {
this.options.rowDelimiter = this.options.rowDelimiter;
this.receivedRowDelimiterAsString = false;
}
} else {
this.options.rowDelimiter = null;
}
if ((base1 = this.options).delimiter == null) {
base1.delimiter = ',';
if ((base = this.options).delimiter == null) {
base.delimiter = ',';
}
if ((base2 = this.options).quote == null) {
base2.quote = '"';
if ((base1 = this.options).quote == null) {
base1.quote = '"';
}
if ((base3 = this.options).escape == null) {
base3.escape = '"';
if ((base2 = this.options).escape == null) {
base2.escape = '"';
}
if ((base4 = this.options).columns == null) {
base4.columns = null;
if ((base3 = this.options).columns == null) {
base3.columns = null;
}
if ((base5 = this.options).comment == null) {
base5.comment = '';
if ((base4 = this.options).comment == null) {
base4.comment = '';
}
if ((base6 = this.options).objname == null) {
base6.objname = false;
if ((base5 = this.options).objname == null) {
base5.objname = false;
}
if ((base7 = this.options).trim == null) {
base7.trim = false;
if ((base6 = this.options).trim == null) {
base6.trim = false;
}
if ((base8 = this.options).ltrim == null) {
base8.ltrim = false;
if ((base7 = this.options).ltrim == null) {
base7.ltrim = false;
}
if ((base9 = this.options).rtrim == null) {
base9.rtrim = false;
if ((base8 = this.options).rtrim == null) {
base8.rtrim = false;
}
if ((base10 = this.options).auto_parse == null) {
base10.auto_parse = false;
if ((base9 = this.options).auto_parse == null) {
base9.auto_parse = false;
}
if ((base11 = this.options).auto_parse_date == null) {
base11.auto_parse_date = false;
if ((base10 = this.options).auto_parse_date == null) {
base10.auto_parse_date = false;
}
if ((base12 = this.options).relax == null) {
base12.relax = false;
if ((base11 = this.options).relax == null) {
base11.relax = false;
}
if ((base13 = this.options).relax_column_count == null) {
base13.relax_column_count = false;
if ((base12 = this.options).relax_column_count == null) {
base12.relax_column_count = false;
}
if ((base14 = this.options).skip_empty_lines == null) {
base14.skip_empty_lines = false;
if ((base13 = this.options).skip_empty_lines == null) {
base13.skip_empty_lines = false;
}
if ((base15 = this.options).max_limit_on_data_read == null) {
base15.max_limit_on_data_read = 128000;
if ((base14 = this.options).max_limit_on_data_read == null) {
base14.max_limit_on_data_read = 128000;
}
if ((base16 = this.options).skip_lines_with_empty_values == null) {
base16.skip_lines_with_empty_values = false;
if ((base15 = this.options).skip_lines_with_empty_values == null) {
base15.skip_lines_with_empty_values = false;
}

@@ -161,2 +169,3 @@ this.lines = 0;

this.rawBuf = '';
this.rowDelimiter = null;
return this;

@@ -202,7 +211,6 @@ };

Parser.prototype.__push = function(line) {
var field, i, j, len, lineAsColumns, rawBuf, row;
var field, i, j, len, lineAsColumns, rawBuf;
if (this.options.skip_lines_with_empty_values && line.join('').trim() === '') {
return;
}
row = null;
if (this.options.columns === true) {

@@ -243,8 +251,6 @@ this.options.columns = line;

if (this.options.objname) {
row = [lineAsColumns[this.options.objname], lineAsColumns];
line = [lineAsColumns[this.options.objname], lineAsColumns];
} else {
row = lineAsColumns;
line = lineAsColumns;
}
} else {
row = line;
}

@@ -254,12 +260,12 @@ if (this.options.raw) {

raw: this.rawBuf,
row: row
row: line
});
return this.rawBuf = '';
} else {
return this.push(row);
return this.push(line);
}
};
Parser.prototype.__write = function(chars, end, callback) {
var areNextCharsDelimiter, areNextCharsRowDelimiters, auto_parse, char, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isQuote, isRowDelimiter, is_float, is_int, l, ltrim, nextCharPos, ref, remainingBuffer, results, rowDelimiter, rowDelimiterLength, rtrim, wasCommenting;
Parser.prototype.__write = function(chars, end) {
var areNextCharsDelimiter, areNextCharsRowDelimiters, auto_parse, char, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isQuote, isRowDelimiter, is_float, is_int, is_rem_buf_rowDelimiter, is_rem_buf_rowDelimiter_following_closing_quote, l, ltrim, match_chars_with_row_delimiters, matched, nextCharPos, ref, ref1, ref2, remainingBuffer, results, rowDelimiter, rtrim, rtrimed, wasCommenting;
is_int = (function(_this) {

@@ -299,2 +305,75 @@ return function(value) {

})(this);
is_rem_buf_rowDelimiter = (function(_this) {
return function(remainingBuffer, remainingBufferLength) {
var j, len, ref, rowDelimiter, rowDelimiterMatched;
rowDelimiterMatched = false;
if (_this.rowDelimiter != null) {
if (remainingBufferLength < _this.rowDelimiter.length && _this.rowDelimiter.substr(0, remainingBufferLength) === remainingBuffer) {
rowDelimiterMatched = true;
}
} else if (_this.options.rowDelimiter != null) {
ref = _this.options.rowDelimiter;
for (j = 0, len = ref.length; j < len; j++) {
rowDelimiter = ref[j];
if (remainingBufferLength < rowDelimiter.length && rowDelimiter.substr(0, remainingBufferLength) === remainingBuffer) {
rowDelimiterMatched = true;
break;
}
}
}
return rowDelimiterMatched;
};
})(this);
is_rem_buf_rowDelimiter_following_closing_quote = (function(_this) {
return function(remainingBuffer, remainingBufferLength) {
var j, len, ref, rowDelimiter, rowDelimiterFollowingClosingQuoteMatched;
rowDelimiterFollowingClosingQuoteMatched = false;
if (_this.rowDelimiter != null) {
if (_this.quoting && remainingBufferLength < (_this.options.quote.length + _this.rowDelimiter.length) && (_this.options.quote + _this.rowDelimiter).substr(0, remainingBufferLength) === remainingBuffer) {
rowDelimiterFollowingClosingQuoteMatched = true;
}
} else if (_this.options.rowDelimiter != null) {
ref = _this.options.rowDelimiter;
for (j = 0, len = ref.length; j < len; j++) {
rowDelimiter = ref[j];
if (_this.quoting && remainingBufferLength < (_this.options.quote.length + rowDelimiter.length) && (_this.options.quote + rowDelimiter).substr(0, remainingBufferLength) === remainingBuffer) {
rowDelimiterFollowingClosingQuoteMatched = true;
break;
}
}
}
return rowDelimiterFollowingClosingQuoteMatched;
};
})(this);
match_chars_with_row_delimiters = (function(_this) {
return function(chars, index) {
var j, len, matchedRowDelimiter, ref, rowDelimiter;
matchedRowDelimiter = null;
if (_this.rowDelimiter != null) {
if (chars.substr(index, _this.rowDelimiter.length) === _this.rowDelimiter) {
matchedRowDelimiter = _this.rowDelimiter;
}
} else if (_this.options.rowDelimiter != null) {
ref = _this.options.rowDelimiter;
for (j = 0, len = ref.length; j < len; j++) {
rowDelimiter = ref[j];
if (chars.substr(index, rowDelimiter.length) === rowDelimiter) {
matchedRowDelimiter = rowDelimiter;
break;
}
}
}
if (matchedRowDelimiter != null) {
return {
rowDelimiter: matchedRowDelimiter,
matched: true
};
} else {
return {
rowDelimiter: matchedRowDelimiter,
matched: false
};
}
};
})(this);
ltrim = this.options.trim || this.options.ltrim;

@@ -304,3 +383,2 @@ rtrim = this.options.trim || this.options.rtrim;

l = chars.length;
rowDelimiterLength = this.options.rowDelimiter ? this.options.rowDelimiter.length : 0;
i = 0;

@@ -313,3 +391,3 @@ if (this.lines === 0 && 0xFEFF === chars.charCodeAt(0)) {

remainingBuffer = chars.substr(i, l - i);
if ((!this.commenting && l - i < this.options.comment.length && this.options.comment.substr(0, l - i) === remainingBuffer) || (this.options.rowDelimiter && l - i < rowDelimiterLength && this.options.rowDelimiter.substr(0, l - i) === remainingBuffer) || (this.options.rowDelimiter && this.quoting && l - i < (this.options.quote.length + rowDelimiterLength) && (this.options.quote + this.options.rowDelimiter).substr(0, l - i) === remainingBuffer) || (l - i <= this.options.delimiter.length && this.options.delimiter.substr(0, l - i) === remainingBuffer) || (l - i <= this.options.escape.length && this.options.escape.substr(0, l - i) === remainingBuffer)) {
if ((!this.commenting && l - i < this.options.comment.length && this.options.comment.substr(0, l - i) === remainingBuffer) || is_rem_buf_rowDelimiter(remainingBuffer, l - i) || is_rem_buf_rowDelimiter_following_closing_quote(remainingBuffer, l - i) || (l - i <= this.options.delimiter.length && this.options.delimiter.substr(0, l - i) === remainingBuffer) || (l - i <= this.options.escape.length && this.options.escape.substr(0, l - i) === remainingBuffer)) {
break;

@@ -323,3 +401,3 @@ }

}
if (this.options.rowDelimiter == null) {
if (!(((ref = this.options.rowDelimiter) != null ? ref.length : void 0) > 0)) {
if ((!this.quoting) && (char === '\n' || char === '\r')) {

@@ -339,4 +417,3 @@ rowDelimiter = char;

}
this.options.rowDelimiter = rowDelimiter;
rowDelimiterLength = this.options.rowDelimiter.length;
this.rowDelimiter = rowDelimiter;
}

@@ -362,3 +439,4 @@ }

if (this.quoting) {
areNextCharsRowDelimiters = this.options.rowDelimiter && chars.substr(i + 1, this.options.rowDelimiter.length) === this.options.rowDelimiter;
ref1 = match_chars_with_row_delimiters(chars, i + 1), matched = ref1.matched, rowDelimiter = ref1.rowDelimiter;
areNextCharsRowDelimiters = matched;
areNextCharsDelimiter = chars.substr(i + 1, this.options.delimiter.length) === this.options.delimiter;

@@ -391,3 +469,4 @@ isNextCharAComment = this.nextChar === this.options.comment;

}
isRowDelimiter = this.options.rowDelimiter && chars.substr(i, this.options.rowDelimiter.length) === this.options.rowDelimiter;
ref2 = match_chars_with_row_delimiters(chars, i), matched = ref2.matched, rowDelimiter = ref2.rowDelimiter;
isRowDelimiter = matched;
if (isRowDelimiter || (end && i === l - 1)) {

@@ -407,3 +486,5 @@ this.lines++;

if (wasCommenting || this.options.skip_empty_lines) {
i += this.options.rowDelimiter.length;
if (rowDelimiter != null) {
i += rowDelimiter.length;
}
this.nextChar = chars.charAt(i);

@@ -432,3 +513,5 @@ continue;

this.line = [];
i += (ref = this.options.rowDelimiter) != null ? ref.length : void 0;
if (rowDelimiter != null) {
i += rowDelimiter.length;
}
this.nextChar = chars.charAt(i);

@@ -457,12 +540,16 @@ continue;

if (!this.commenting && this.line.length > this.options.max_limit_on_data_read) {
throw Error("Row delimiter not found in the file " + (JSON.stringify(this.options.rowDelimiter)));
if (this.receivedRowDelimiterAsString) {
throw Error("Row delimiter(s) not found in the file " + (JSON.stringify(this.options.rowDelimiter[0])));
} else {
throw Error("Row delimiter(s) not found in the file " + (JSON.stringify(this.options.rowDelimiter)));
}
}
}
if (end) {
if (rtrim) {
if (!this.closingQuote) {
this.field = this.field.trimRight();
}
rtrimed = false;
if (rtrim && !this.closingQuote) {
this.field = this.field.trimRight();
rtrimed = true;
}
if (this.field !== '') {
if (this.field !== '' || rtrimed) {
this.line.push(auto_parse(this.field));

@@ -478,3 +565,7 @@ this.field = '';

if (this.line.length > this.options.max_limit_on_data_read) {
throw Error("Row delimiter not found in the file " + (JSON.stringify(this.options.rowDelimiter)));
if (this.receivedRowDelimiterAsString) {
throw Error("Row delimiter(s) not found in the file " + (JSON.stringify(this.options.rowDelimiter[0])));
} else {
throw Error("Row delimiter(s) not found in the file " + (JSON.stringify(this.options.rowDelimiter)));
}
}

@@ -481,0 +572,0 @@ }

{
"version": "1.1.7",
"version": "1.1.8",
"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