Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
refactor: rename state wasRecordDelimiter to wasRowDelimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Feb 1, 2021
1 parent 77fa209 commit afa0bc5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
18 changes: 9 additions & 9 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6995,7 +6995,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,
wasRecordDelimiter: false
wasRowDelimiter: false
}
}
// Implementation of `Transform._transform`
Expand Down Expand Up @@ -7068,12 +7068,12 @@ class Parser extends Transform {
if(this.__needMoreData(pos, bufLen, end)){
break
}
if(this.state.wasRecordDelimiter === true){
if(this.state.wasRowDelimiter === 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.wasRecordDelimiter = false
this.state.wasRowDelimiter = false
}
if(to_line !== -1 && this.info.lines > to_line){
this.state.stop = true
Expand All @@ -7091,8 +7091,8 @@ class Parser extends Transform {
if(raw === true){
rawBuffer.append(chr)
}
if((chr === cr || chr === nl) && this.state.wasRecordDelimiter === false ){
this.state.wasRecordDelimiter = true
if((chr === cr || chr === nl) && this.state.wasRowDelimiter === false ){
this.state.wasRowDelimiter = true
}
// Previous char was a valid escape char
// treat the current char as a regular char
Expand Down Expand Up @@ -7187,7 +7187,7 @@ class Parser extends Transform {
continue
}
// Activate records emition if above from_line
if(this.state.enabled === false && this.info.lines + (this.state.wasRecordDelimiter === true ? 1: 0 ) >= from_line){
if(this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1: 0 ) >= from_line){
this.state.enabled = true
this.__resetField()
this.__resetRecord()
Expand Down Expand Up @@ -7273,7 +7273,7 @@ class Parser extends Transform {
if(errField !== undefined) return errField
const errRecord = this.__onRecord()
if(errRecord !== undefined) return errRecord
}else if(this.state.wasRecordDelimiter === true){
}else if(this.state.wasRowDelimiter === true){
this.info.empty_lines++
}else if(this.state.commenting === true){
this.info.comment_lines++
Expand All @@ -7282,9 +7282,9 @@ class Parser extends Transform {
}else{
this.state.previousBuf = buf.slice(pos)
}
if(this.state.wasRecordDelimiter === true){
if(this.state.wasRowDelimiter === true){
this.info.lines++
this.state.wasRecordDelimiter = false
this.state.wasRowDelimiter = false
}
}
__onRecord(){
Expand Down
18 changes: 9 additions & 9 deletions lib/browser/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6995,7 +6995,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,
wasRecordDelimiter: false
wasRowDelimiter: false
}
}
// Implementation of `Transform._transform`
Expand Down Expand Up @@ -7068,12 +7068,12 @@ class Parser extends Transform {
if(this.__needMoreData(pos, bufLen, end)){
break
}
if(this.state.wasRecordDelimiter === true){
if(this.state.wasRowDelimiter === 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.wasRecordDelimiter = false
this.state.wasRowDelimiter = false
}
if(to_line !== -1 && this.info.lines > to_line){
this.state.stop = true
Expand All @@ -7091,8 +7091,8 @@ class Parser extends Transform {
if(raw === true){
rawBuffer.append(chr)
}
if((chr === cr || chr === nl) && this.state.wasRecordDelimiter === false ){
this.state.wasRecordDelimiter = true
if((chr === cr || chr === nl) && this.state.wasRowDelimiter === false ){
this.state.wasRowDelimiter = true
}
// Previous char was a valid escape char
// treat the current char as a regular char
Expand Down Expand Up @@ -7187,7 +7187,7 @@ class Parser extends Transform {
continue
}
// Activate records emition if above from_line
if(this.state.enabled === false && this.info.lines + (this.state.wasRecordDelimiter === true ? 1: 0 ) >= from_line){
if(this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1: 0 ) >= from_line){
this.state.enabled = true
this.__resetField()
this.__resetRecord()
Expand Down Expand Up @@ -7273,7 +7273,7 @@ class Parser extends Transform {
if(errField !== undefined) return errField
const errRecord = this.__onRecord()
if(errRecord !== undefined) return errRecord
}else if(this.state.wasRecordDelimiter === true){
}else if(this.state.wasRowDelimiter === true){
this.info.empty_lines++
}else if(this.state.commenting === true){
this.info.comment_lines++
Expand All @@ -7282,9 +7282,9 @@ class Parser extends Transform {
}else{
this.state.previousBuf = buf.slice(pos)
}
if(this.state.wasRecordDelimiter === true){
if(this.state.wasRowDelimiter === true){
this.info.lines++
this.state.wasRecordDelimiter = false
this.state.wasRowDelimiter = false
}
}
__onRecord(){
Expand Down
18 changes: 9 additions & 9 deletions lib/es5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
}))),
trimChars: [Buffer.from(' ', options.encoding)[0], Buffer.from('\t', options.encoding)[0]],
wasQuoting: false,
wasRecordDelimiter: false
wasRowDelimiter: false
};
} // Implementation of `Transform._transform`

Expand Down Expand Up @@ -642,14 +642,14 @@ var Parser = /*#__PURE__*/function (_Transform) {
break;
}

if (this.state.wasRecordDelimiter === true) {
if (this.state.wasRowDelimiter === 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.wasRecordDelimiter = false;
this.state.wasRowDelimiter = false;
}

if (to_line !== -1 && this.info.lines > to_line) {
Expand All @@ -673,8 +673,8 @@ var Parser = /*#__PURE__*/function (_Transform) {
rawBuffer.append(chr);
}

if ((chr === cr || chr === nl) && this.state.wasRecordDelimiter === false) {
this.state.wasRecordDelimiter = true;
if ((chr === cr || chr === nl) && this.state.wasRowDelimiter === false) {
this.state.wasRowDelimiter = true;
} // Previous char was a valid escape char
// treat the current char as a regular char

Expand Down Expand Up @@ -767,7 +767,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
} // Activate records emition if above from_line


if (this.state.enabled === false && this.info.lines + (this.state.wasRecordDelimiter === true ? 1 : 0) >= from_line) {
if (this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1 : 0) >= from_line) {
this.state.enabled = true;

this.__resetField();
Expand Down Expand Up @@ -858,7 +858,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
var _errRecord = this.__onRecord();

if (_errRecord !== undefined) return _errRecord;
} else if (this.state.wasRecordDelimiter === true) {
} else if (this.state.wasRowDelimiter === true) {
this.info.empty_lines++;
} else if (this.state.commenting === true) {
this.info.comment_lines++;
Expand All @@ -868,9 +868,9 @@ var Parser = /*#__PURE__*/function (_Transform) {
this.state.previousBuf = buf.slice(pos);
}

if (this.state.wasRecordDelimiter === true) {
if (this.state.wasRowDelimiter === true) {
this.info.lines++;
this.state.wasRecordDelimiter = false;
this.state.wasRowDelimiter = false;
}
}
}, {
Expand Down
18 changes: 9 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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,
wasRecordDelimiter: false
wasRowDelimiter: false
}
}
// Implementation of `Transform._transform`
Expand Down Expand Up @@ -529,12 +529,12 @@ class Parser extends Transform {
if(this.__needMoreData(pos, bufLen, end)){
break
}
if(this.state.wasRecordDelimiter === true){
if(this.state.wasRowDelimiter === 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.wasRecordDelimiter = false
this.state.wasRowDelimiter = false
}
if(to_line !== -1 && this.info.lines > to_line){
this.state.stop = true
Expand All @@ -552,8 +552,8 @@ class Parser extends Transform {
if(raw === true){
rawBuffer.append(chr)
}
if((chr === cr || chr === nl) && this.state.wasRecordDelimiter === false ){
this.state.wasRecordDelimiter = true
if((chr === cr || chr === nl) && this.state.wasRowDelimiter === false ){
this.state.wasRowDelimiter = true
}
// Previous char was a valid escape char
// treat the current char as a regular char
Expand Down Expand Up @@ -648,7 +648,7 @@ class Parser extends Transform {
continue
}
// Activate records emition if above from_line
if(this.state.enabled === false && this.info.lines + (this.state.wasRecordDelimiter === true ? 1: 0 ) >= from_line){
if(this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1: 0 ) >= from_line){
this.state.enabled = true
this.__resetField()
this.__resetRecord()
Expand Down Expand Up @@ -734,7 +734,7 @@ class Parser extends Transform {
if(errField !== undefined) return errField
const errRecord = this.__onRecord()
if(errRecord !== undefined) return errRecord
}else if(this.state.wasRecordDelimiter === true){
}else if(this.state.wasRowDelimiter === true){
this.info.empty_lines++
}else if(this.state.commenting === true){
this.info.comment_lines++
Expand All @@ -743,9 +743,9 @@ class Parser extends Transform {
}else{
this.state.previousBuf = buf.slice(pos)
}
if(this.state.wasRecordDelimiter === true){
if(this.state.wasRowDelimiter === true){
this.info.lines++
this.state.wasRecordDelimiter = false
this.state.wasRowDelimiter = false
}
}
__onRecord(){
Expand Down
2 changes: 1 addition & 1 deletion test/option.from_line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe 'Option `from_line`', ->
] unless err
next err

it 'not influenced by record delimiters', (next) ->
it 'not influenced by `record_delimiter` option', (next) ->
parse """
a,b,c:1,2,
3:d,e,f:4,5,
Expand Down

0 comments on commit afa0bc5

Please sign in to comment.