diff --git a/lib/es5/index.js b/lib/es5/index.js index eb9e244..08cf2b5 100644 --- a/lib/es5/index.js +++ b/lib/es5/index.js @@ -514,7 +514,7 @@ var Parser = /*#__PURE__*/function (_Transform) { }))), trimChars: [Buffer.from(' ', options.encoding)[0], Buffer.from('\t', options.encoding)[0]], wasQuoting: false, - wasRowDelimiter: false + wasRecordDelimiter: false }; } // Implementation of `Transform._transform` @@ -625,14 +625,14 @@ var Parser = /*#__PURE__*/function (_Transform) { break; } - if (this.state.wasRowDelimiter === true) { + if (this.state.wasRecordDelimiter === true) { this.info.lines++; if (info === true && this.state.record.length === 0 && this.state.field.length === 0 && this.state.wasQuoting === false) { this.state.info = Object.assign({}, this.info); } - this.state.wasRowDelimiter = false; + this.state.wasRecordDelimiter = false; } if (to_line !== -1 && this.info.lines > to_line) { @@ -643,7 +643,7 @@ var Parser = /*#__PURE__*/function (_Transform) { if (this.state.quoting === false && record_delimiter.length === 0) { - var record_delimiterCount = this.__autoDiscoverRowDelimiter(buf, pos); + var record_delimiterCount = this.__autoDiscoverRecordDelimiter(buf, pos); if (record_delimiterCount) { record_delimiter = this.options.record_delimiter; @@ -656,8 +656,8 @@ var Parser = /*#__PURE__*/function (_Transform) { rawBuffer.append(chr); } - if ((chr === cr || chr === nl) && this.state.wasRowDelimiter === false) { - this.state.wasRowDelimiter = true; + if ((chr === cr || chr === nl) && this.state.wasRecordDelimiter === false) { + this.state.wasRecordDelimiter = true; } // Previous char was a valid escape char // treat the current char as a regular char @@ -694,18 +694,18 @@ var Parser = /*#__PURE__*/function (_Transform) { var isNextChrDelimiter = this.__isDelimiter(buf, pos + quote.length, nextChr); - var isNextChrRowDelimiter = record_delimiter.length === 0 ? this.__autoDiscoverRowDelimiter(buf, pos + quote.length) : this.__isRecordDelimiter(nextChr, buf, pos + quote.length); // Escape a quote + var isNextChrRecordDelimiter = record_delimiter.length === 0 ? this.__autoDiscoverRecordDelimiter(buf, pos + quote.length) : this.__isRecordDelimiter(nextChr, buf, pos + quote.length); // Escape a quote // Treat next char as a regular character if (escape !== null && this.__isEscape(buf, pos, chr) && this.__isQuote(buf, pos + escape.length)) { pos += escape.length - 1; - } else if (!nextChr || isNextChrDelimiter || isNextChrRowDelimiter || isNextChrComment || isNextChrTrimable) { + } else if (!nextChr || isNextChrDelimiter || isNextChrRecordDelimiter || isNextChrComment || isNextChrTrimable) { this.state.quoting = false; this.state.wasQuoting = true; pos += quote.length - 1; continue; } else if (relax === false) { - var err = this.__error(new CsvError('CSV_INVALID_CLOSING_QUOTE', ['Invalid Closing Quote:', "got \"".concat(String.fromCharCode(nextChr), "\""), "at line ".concat(this.info.lines), 'instead of delimiter, row delimiter, trimable character', '(if activated) or comment'], this.options, this.__context())); + var err = this.__error(new CsvError('CSV_INVALID_CLOSING_QUOTE', ['Invalid Closing Quote:', "got \"".concat(String.fromCharCode(nextChr), "\""), "at line ".concat(this.info.lines), 'instead of delimiter, record delimiter, trimable character', '(if activated) or comment'], this.options, this.__context())); if (err !== undefined) return err; } else { @@ -750,12 +750,12 @@ var Parser = /*#__PURE__*/function (_Transform) { } // Activate records emition if above from_line - if (this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1 : 0) >= from_line) { + if (this.state.enabled === false && this.info.lines + (this.state.wasRecordDelimiter === true ? 1 : 0) >= from_line) { this.state.enabled = true; this.__resetField(); - this.__resetRow(); + this.__resetRecord(); pos += recordDelimiterLength - 1; continue; @@ -764,7 +764,7 @@ var Parser = /*#__PURE__*/function (_Transform) { if (errField !== undefined) return errField; - var errRecord = this.__onRow(); + var errRecord = this.__onRecord(); if (errRecord !== undefined) return errRecord; } @@ -838,10 +838,10 @@ var Parser = /*#__PURE__*/function (_Transform) { if (_errField2 !== undefined) return _errField2; - var _errRecord = this.__onRow(); + var _errRecord = this.__onRecord(); if (_errRecord !== undefined) return _errRecord; - } else if (this.state.wasRowDelimiter === true) { + } else if (this.state.wasRecordDelimiter === true) { this.info.empty_lines++; } else if (this.state.commenting === true) { this.info.comment_lines++; @@ -851,14 +851,14 @@ var Parser = /*#__PURE__*/function (_Transform) { this.state.previousBuf = buf.slice(pos); } - if (this.state.wasRowDelimiter === true) { + if (this.state.wasRecordDelimiter === true) { this.info.lines++; - this.state.wasRowDelimiter = false; + this.state.wasRecordDelimiter = false; } } }, { - key: "__onRow", - value: function __onRow() { + key: "__onRecord", + value: function __onRecord() { var _this$options2 = this.options, columns = _this$options2.columns, columns_duplicates_to_array = _this$options2.columns_duplicates_to_array, @@ -875,7 +875,7 @@ var Parser = /*#__PURE__*/function (_Transform) { record = _this$state2.record; if (enabled === false) { - return this.__resetRow(); + return this.__resetRecord(); } // Convert the first line into column names @@ -883,7 +883,7 @@ var Parser = /*#__PURE__*/function (_Transform) { if (columns === true) { if (isRecordEmpty(record)) { - this.__resetRow(); + this.__resetRecord(); return; } @@ -919,14 +919,14 @@ var Parser = /*#__PURE__*/function (_Transform) { if (skip_lines_with_empty_values === true) { if (isRecordEmpty(record)) { - this.__resetRow(); + this.__resetRecord(); return; } } if (this.state.recordHasError === true) { - this.__resetRow(); + this.__resetRecord(); this.state.recordHasError = false; return; @@ -1018,7 +1018,7 @@ var Parser = /*#__PURE__*/function (_Transform) { } } - this.__resetRow(); + this.__resetRecord(); } }, { key: "__firstLineToColumns", @@ -1038,7 +1038,7 @@ var Parser = /*#__PURE__*/function (_Transform) { this.state.expectedRecordLength = normalizedHeaders.length; this.options.columns = normalizedHeaders; - this.__resetRow(); + this.__resetRecord(); return; } catch (err) { @@ -1046,8 +1046,8 @@ var Parser = /*#__PURE__*/function (_Transform) { } } }, { - key: "__resetRow", - value: function __resetRow() { + key: "__resetRecord", + value: function __resetRecord() { if (this.options.raw === true) { this.state.rawBuffer.reset(); } @@ -1197,7 +1197,7 @@ var Parser = /*#__PURE__*/function (_Transform) { recordDelimiterMaxLength = _this$state4.recordDelimiterMaxLength; var numOfCharLeft = bufLen - i - 1; var requiredLength = Math.max(needMoreDataSize, // Skip if the remaining buffer smaller than record delimiter - recordDelimiterMaxLength, // Skip if the remaining buffer can be row delimiter following the closing quote + recordDelimiterMaxLength, // Skip if the remaining buffer can be record delimiter following the closing quote // 1 is for quote.length quoting ? quote.length + recordDelimiterMaxLength : 0); return numOfCharLeft < requiredLength; @@ -1281,8 +1281,8 @@ var Parser = /*#__PURE__*/function (_Transform) { return true; } }, { - key: "__autoDiscoverRowDelimiter", - value: function __autoDiscoverRowDelimiter(buf, pos) { + key: "__autoDiscoverRecordDelimiter", + value: function __autoDiscoverRecordDelimiter(buf, pos) { var encoding = this.options.encoding; var chr = buf[pos]; diff --git a/lib/index.js b/lib/index.js index e3bcf32..65df830 100644 --- a/lib/index.js +++ b/lib/index.js @@ -435,7 +435,7 @@ class Parser extends Transform { recordDelimiterMaxLength: options.record_delimiter.length === 0 ? 2 : Math.max(...options.record_delimiter.map( (v) => v.length)), trimChars: [Buffer.from(' ', options.encoding)[0], Buffer.from('\t', options.encoding)[0]], wasQuoting: false, - wasRowDelimiter: false + wasRecordDelimiter: false } } // Implementation of `Transform._transform` @@ -508,12 +508,12 @@ class Parser extends Transform { if(this.__needMoreData(pos, bufLen, end)){ break } - if(this.state.wasRowDelimiter === true){ + if(this.state.wasRecordDelimiter === true){ this.info.lines++ if(info === true && this.state.record.length === 0 && this.state.field.length === 0 && this.state.wasQuoting === false){ this.state.info = Object.assign({}, this.info) } - this.state.wasRowDelimiter = false + this.state.wasRecordDelimiter = false } if(to_line !== -1 && this.info.lines > to_line){ this.state.stop = true @@ -522,7 +522,7 @@ class Parser extends Transform { } // Auto discovery of record_delimiter, unix, mac and windows supported if(this.state.quoting === false && record_delimiter.length === 0){ - const record_delimiterCount = this.__autoDiscoverRowDelimiter(buf, pos) + const record_delimiterCount = this.__autoDiscoverRecordDelimiter(buf, pos) if(record_delimiterCount){ record_delimiter = this.options.record_delimiter } @@ -531,8 +531,8 @@ class Parser extends Transform { if(raw === true){ rawBuffer.append(chr) } - if((chr === cr || chr === nl) && this.state.wasRowDelimiter === false ){ - this.state.wasRowDelimiter = true + if((chr === cr || chr === nl) && this.state.wasRecordDelimiter === false ){ + this.state.wasRecordDelimiter = true } // Previous char was a valid escape char // treat the current char as a regular char @@ -563,12 +563,12 @@ class Parser extends Transform { const isNextChrTrimable = rtrim && this.__isCharTrimable(nextChr) const isNextChrComment = comment !== null && this.__compareBytes(comment, buf, pos+quote.length, nextChr) const isNextChrDelimiter = this.__isDelimiter(buf, pos+quote.length, nextChr) - const isNextChrRowDelimiter = record_delimiter.length === 0 ? this.__autoDiscoverRowDelimiter(buf, pos+quote.length) : this.__isRecordDelimiter(nextChr, buf, pos+quote.length) + const isNextChrRecordDelimiter = record_delimiter.length === 0 ? this.__autoDiscoverRecordDelimiter(buf, pos+quote.length) : this.__isRecordDelimiter(nextChr, buf, pos+quote.length) // Escape a quote // Treat next char as a regular character if(escape !== null && this.__isEscape(buf, pos, chr) && this.__isQuote(buf, pos + escape.length)){ pos += escape.length - 1 - }else if(!nextChr || isNextChrDelimiter || isNextChrRowDelimiter || isNextChrComment || isNextChrTrimable){ + }else if(!nextChr || isNextChrDelimiter || isNextChrRecordDelimiter || isNextChrComment || isNextChrTrimable){ this.state.quoting = false this.state.wasQuoting = true pos += quote.length - 1 @@ -579,7 +579,7 @@ class Parser extends Transform { 'Invalid Closing Quote:', `got "${String.fromCharCode(nextChr)}"`, `at line ${this.info.lines}`, - 'instead of delimiter, row delimiter, trimable character', + 'instead of delimiter, record delimiter, trimable character', '(if activated) or comment', ], this.options, this.__context()) ) @@ -627,16 +627,16 @@ class Parser extends Transform { continue } // Activate records emition if above from_line - if(this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1: 0 ) >= from_line){ + if(this.state.enabled === false && this.info.lines + (this.state.wasRecordDelimiter === true ? 1: 0 ) >= from_line){ this.state.enabled = true this.__resetField() - this.__resetRow() + this.__resetRecord() pos += recordDelimiterLength - 1 continue }else{ const errField = this.__onField() if(errField !== undefined) return errField - const errRecord = this.__onRow() + const errRecord = this.__onRecord() if(errRecord !== undefined) return errRecord } if(to !== -1 && this.info.records >= to){ @@ -711,9 +711,9 @@ class Parser extends Transform { if(this.state.wasQuoting === true || this.state.record.length !== 0 || this.state.field.length !== 0){ const errField = this.__onField() if(errField !== undefined) return errField - const errRecord = this.__onRow() + const errRecord = this.__onRecord() if(errRecord !== undefined) return errRecord - }else if(this.state.wasRowDelimiter === true){ + }else if(this.state.wasRecordDelimiter === true){ this.info.empty_lines++ }else if(this.state.commenting === true){ this.info.comment_lines++ @@ -722,22 +722,22 @@ class Parser extends Transform { }else{ this.state.previousBuf = buf.slice(pos) } - if(this.state.wasRowDelimiter === true){ + if(this.state.wasRecordDelimiter === true){ this.info.lines++ - this.state.wasRowDelimiter = false + this.state.wasRecordDelimiter = false } } - __onRow(){ + __onRecord(){ const {columns, columns_duplicates_to_array, encoding, 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 if(enabled === false){ - return this.__resetRow() + return this.__resetRecord() } // Convert the first line into column names const recordLength = record.length if(columns === true){ if(isRecordEmpty(record)){ - this.__resetRow() + this.__resetRecord() return } return this.__firstLineToColumns(record) @@ -779,12 +779,12 @@ class Parser extends Transform { } if(skip_lines_with_empty_values === true){ if(isRecordEmpty(record)){ - this.__resetRow() + this.__resetRecord() return } } if(this.state.recordHasError === true){ - this.__resetRow() + this.__resetRecord() this.state.recordHasError = false return } @@ -858,7 +858,7 @@ class Parser extends Transform { } } } - this.__resetRow() + this.__resetRecord() } __firstLineToColumns(record){ const {firstLineToHeaders} = this.state @@ -878,13 +878,13 @@ class Parser extends Transform { const normalizedHeaders = normalizeColumnsArray(headers) this.state.expectedRecordLength = normalizedHeaders.length this.options.columns = normalizedHeaders - this.__resetRow() + this.__resetRecord() return }catch(err){ return err } } - __resetRow(){ + __resetRecord(){ if(this.options.raw === true){ this.state.rawBuffer.reset() } @@ -987,7 +987,7 @@ class Parser extends Transform { needMoreDataSize, // Skip if the remaining buffer smaller than record delimiter recordDelimiterMaxLength, - // Skip if the remaining buffer can be row delimiter following the closing quote + // Skip if the remaining buffer can be record delimiter following the closing quote // 1 is for quote.length quoting ? (quote.length + recordDelimiterMaxLength) : 0, ) @@ -1049,7 +1049,7 @@ class Parser extends Transform { } return true } - __autoDiscoverRowDelimiter(buf, pos){ + __autoDiscoverRecordDelimiter(buf, pos){ const {encoding} = this.options const chr = buf[pos] if(chr === cr){ diff --git a/test/info.lines.coffee b/test/info.lines.coffee index 3f5e6fc..82822fd 100644 --- a/test/info.lines.coffee +++ b/test/info.lines.coffee @@ -87,7 +87,7 @@ describe 'properties lines', -> " 1974 8.8392926E7 "t "" """, quote: '"', escape: '"', delimiter: "\t", (err, data) -> assert_error err, - message: 'Invalid Closing Quote: got " " at line 3 instead of delimiter, row delimiter, trimable character (if activated) or comment' + message: 'Invalid Closing Quote: got " " at line 3 instead of delimiter, record delimiter, trimable character (if activated) or comment' code: 'CSV_INVALID_CLOSING_QUOTE' (data == undefined).should.be.true next() @@ -102,7 +102,7 @@ describe 'properties lines', -> "",1974,8.8392926E7,""t,"" """, quote: '"', escape: '"', (err, data) -> assert_error err, - message: 'Invalid Closing Quote: got "t" at line 2 instead of delimiter, row delimiter, trimable character (if activated) or comment' + message: 'Invalid Closing Quote: got "t" at line 2 instead of delimiter, record delimiter, trimable character (if activated) or comment' code: 'CSV_INVALID_CLOSING_QUOTE' (data == undefined).should.be.true next() diff --git a/test/option.from.coffee b/test/option.from.coffee index fa0497e..29b6636 100644 --- a/test/option.from.coffee +++ b/test/option.from.coffee @@ -59,7 +59,7 @@ describe 'Option `from`', -> ] unless err next err - it 'not influenced by row delimiter', (next) -> + it 'not influenced by record delimiter', (next) -> parse """ 1,2,3:4,5,6:7,8,9 """, from: 3, record_delimiter: ':', (err, data) -> diff --git a/test/option.ltrim.coffee b/test/option.ltrim.coffee index 6139ee8..67aa91f 100644 --- a/test/option.ltrim.coffee +++ b/test/option.ltrim.coffee @@ -26,7 +26,7 @@ describe 'Option `ltrim`', -> it 'quote followed by escape', (next) -> # 1st line: with start of file # 2nd line: with field delimiter - # 3rd line: with row delimiter + # 3rd line: with record delimiter parse """ '''a','''b' '''c', '''d' diff --git a/test/option.objname.coffee b/test/option.objname.coffee index fc7ee9f..0463a80 100644 --- a/test/option.objname.coffee +++ b/test/option.objname.coffee @@ -55,7 +55,7 @@ describe 'Option `objname`', -> ) unless err next err - it 'should print object of objects with properties using value of given column from header row', (next) -> + it 'should print object of objects with properties using value of given column from header record', (next) -> parse """ FIELD_1,FIELD_2,FIELD_3,FIELD_4,FIELD_5,FIELD_6 20322051544,1979,8.8017226E7,ABC,45,2000-01-01 diff --git a/test/option.quote.coffee b/test/option.quote.coffee index ac7d4f4..1356d29 100644 --- a/test/option.quote.coffee +++ b/test/option.quote.coffee @@ -173,7 +173,7 @@ describe 'Option `quote`', -> it 'when followed by a character', (next) -> parse '""!', quote: '"', escape: '"', (err) -> assert_error err, - message: 'Invalid Closing Quote: got "!" at line 1 instead of delimiter, row delimiter, trimable character (if activated) or comment' + message: 'Invalid Closing Quote: got "!" at line 1 instead of delimiter, record delimiter, trimable character (if activated) or comment' code: 'CSV_INVALID_CLOSING_QUOTE' next() @@ -185,7 +185,7 @@ describe 'Option `quote`', -> parse '""|BB', quote: '"', escape: '"', delimiter: '|', (err) -> next err - it 'no throw followed by a row delimiter', (next) -> + it 'no throw followed by a record delimiter', (next) -> parse '""|BB', quote: '"', escape: '"', record_delimiter: '|', (err) -> next err diff --git a/test/option.record_delimiter.coffee b/test/option.record_delimiter.coffee index eec08bb..30f3d1d 100644 --- a/test/option.record_delimiter.coffee +++ b/test/option.record_delimiter.coffee @@ -166,7 +166,7 @@ describe 'Option `record_delimiter`', -> describe 'auto', -> - it 'No rows', (next) -> + it 'No record', (next) -> # not sure if the current behavior is right, # the new behavior is proposing [['']] # which kind of look more appropriate @@ -211,7 +211,7 @@ describe 'Option `record_delimiter`', -> parser.write 'def,456' parser.end() - it 'Test line ends with field delimiter and without row delimiter', (next) -> + it 'Test line ends with field delimiter and without record delimiter', (next) -> parse '"a","b","c",', delimiter: ',', (err, data) -> return next err if err data.should.eql [ @@ -239,7 +239,7 @@ describe 'Option `record_delimiter`', -> parser.write 'JKL,02\r\n' parser.end() - it 'skip default row delimiters when quoted', (next) -> + it 'skip default record delimiters when quoted', (next) -> parser = parse (err, data) -> # record_delimiter: '\r\n', data.should.eql [ ['1', '2', '\n'] diff --git a/test/option.relax.coffee b/test/option.relax.coffee index 955957a..5cc37dc 100644 --- a/test/option.relax.coffee +++ b/test/option.relax.coffee @@ -57,7 +57,7 @@ describe 'Option `relax`', -> a,"b" c,d """, relax: false, (err, data) -> assert_error err, - message: 'Invalid Closing Quote: got " " at line 1 instead of delimiter, row delimiter, trimable character (if activated) or comment' + message: 'Invalid Closing Quote: got " " at line 1 instead of delimiter, record delimiter, trimable character (if activated) or comment' code: 'CSV_INVALID_CLOSING_QUOTE' next() @@ -82,7 +82,7 @@ describe 'Option `relax`', -> # [ 'a', '"b" c', 'd' ] # ] unless err assert_error err, - message: 'Invalid Closing Quote: got "b" at line 1 instead of delimiter, row delimiter, trimable character (if activated) or comment' + message: 'Invalid Closing Quote: got "b" at line 1 instead of delimiter, record delimiter, trimable character (if activated) or comment' code: 'CSV_INVALID_CLOSING_QUOTE' next() diff --git a/test/option.rtrim.coffee b/test/option.rtrim.coffee index 5040b45..b288022 100644 --- a/test/option.rtrim.coffee +++ b/test/option.rtrim.coffee @@ -25,7 +25,7 @@ describe 'Option `rtrim`', -> it 'quote followed by escape', (next) -> # 1st line: with field delimiter - # 2nd line: with row delimiter + # 2nd line: with record delimiter # 3rd line: with end of file parse """ 'a''' ,'b''' diff --git a/test/option.skip_lines_with_error.coffee b/test/option.skip_lines_with_error.coffee index 69e9db5..4ef531e 100644 --- a/test/option.skip_lines_with_error.coffee +++ b/test/option.skip_lines_with_error.coffee @@ -28,7 +28,7 @@ describe 'Option `skip_lines_with_error`', -> next err parser.on 'skip', (err) -> assert_error err, - message: 'Invalid Closing Quote: got " " at line 3 instead of delimiter, row delimiter, trimable character (if activated) or comment' + message: 'Invalid Closing Quote: got " " at line 3 instead of delimiter, record delimiter, trimable character (if activated) or comment' code: 'CSV_INVALID_CLOSING_QUOTE' errors++ parser.write ''' diff --git a/test/option.to.coffee b/test/option.to.coffee index e74bcd2..da0fd86 100644 --- a/test/option.to.coffee +++ b/test/option.to.coffee @@ -80,7 +80,7 @@ describe 'Option `to`', -> ] unless err next err - it 'not influenced by row delimiter', (next) -> + it 'not influenced by record delimiter', (next) -> parse """ 1,2,3:4,5,6:7,8,9 """, to: 2, record_delimiter: ':', (err, data) -> diff --git a/test/option.to_line.coffee b/test/option.to_line.coffee index 5e81656..40cd0af 100644 --- a/test/option.to_line.coffee +++ b/test/option.to_line.coffee @@ -84,7 +84,7 @@ describe 'Option `to_line`', -> ] unless err next err - it 'not influenced by row delimiter', (next) -> + it 'not influenced by record delimiter', (next) -> parse """ a,b,c:1,2, 3:d,e,f:4,5,