Skip to content

Commit 2741990

Browse files
committed
feat(csv-parse): skip_line_with_errors used with raw print current buffer (fix #292)
1 parent 2c2623f commit 2741990

15 files changed

Lines changed: 71 additions & 40 deletions

File tree

packages/csv-parse/dist/cjs/index.cjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6172,11 +6172,11 @@ class Parser extends Transform {
61726172
return 0;
61736173
}
61746174
__error(msg){
6175-
const {skip_lines_with_error} = this.options;
6175+
const {encoding, raw, skip_lines_with_error} = this.options;
61766176
const err = typeof msg === 'string' ? new Error(msg) : msg;
61776177
if(skip_lines_with_error){
61786178
this.state.recordHasError = true;
6179-
this.emit('skip', err);
6179+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
61806180
return undefined;
61816181
}else {
61826182
return err;
@@ -6189,12 +6189,13 @@ class Parser extends Transform {
61896189
};
61906190
}
61916191
__infoRecord(){
6192-
const {columns} = this.options;
6192+
const {columns, raw, encoding} = this.options;
61936193
return {
61946194
...this.__infoDataSet(),
61956195
error: this.state.error,
61966196
header: columns === true,
61976197
index: this.state.record.length,
6198+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
61986199
};
61996200
}
62006201
__infoField(){

packages/csv-parse/dist/cjs/sync.cjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6172,11 +6172,11 @@ class Parser extends Transform {
61726172
return 0;
61736173
}
61746174
__error(msg){
6175-
const {skip_lines_with_error} = this.options;
6175+
const {encoding, raw, skip_lines_with_error} = this.options;
61766176
const err = typeof msg === 'string' ? new Error(msg) : msg;
61776177
if(skip_lines_with_error){
61786178
this.state.recordHasError = true;
6179-
this.emit('skip', err);
6179+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
61806180
return undefined;
61816181
}else {
61826182
return err;
@@ -6189,12 +6189,13 @@ class Parser extends Transform {
61896189
};
61906190
}
61916191
__infoRecord(){
6192-
const {columns} = this.options;
6192+
const {columns, raw, encoding} = this.options;
61936193
return {
61946194
...this.__infoDataSet(),
61956195
error: this.state.error,
61966196
header: columns === true,
61976197
index: this.state.record.length,
6198+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
61986199
};
61996200
}
62006201
__infoField(){

packages/csv-parse/dist/esm/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6168,11 +6168,11 @@ class Parser extends Transform {
61686168
return 0;
61696169
}
61706170
__error(msg){
6171-
const {skip_lines_with_error} = this.options;
6171+
const {encoding, raw, skip_lines_with_error} = this.options;
61726172
const err = typeof msg === 'string' ? new Error(msg) : msg;
61736173
if(skip_lines_with_error){
61746174
this.state.recordHasError = true;
6175-
this.emit('skip', err);
6175+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
61766176
return undefined;
61776177
}else {
61786178
return err;
@@ -6185,12 +6185,13 @@ class Parser extends Transform {
61856185
};
61866186
}
61876187
__infoRecord(){
6188-
const {columns} = this.options;
6188+
const {columns, raw, encoding} = this.options;
61896189
return {
61906190
...this.__infoDataSet(),
61916191
error: this.state.error,
61926192
header: columns === true,
61936193
index: this.state.record.length,
6194+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
61946195
};
61956196
}
61966197
__infoField(){

packages/csv-parse/dist/esm/sync.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6168,11 +6168,11 @@ class Parser extends Transform {
61686168
return 0;
61696169
}
61706170
__error(msg){
6171-
const {skip_lines_with_error} = this.options;
6171+
const {encoding, raw, skip_lines_with_error} = this.options;
61726172
const err = typeof msg === 'string' ? new Error(msg) : msg;
61736173
if(skip_lines_with_error){
61746174
this.state.recordHasError = true;
6175-
this.emit('skip', err);
6175+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
61766176
return undefined;
61776177
}else {
61786178
return err;
@@ -6185,12 +6185,13 @@ class Parser extends Transform {
61856185
};
61866186
}
61876187
__infoRecord(){
6188-
const {columns} = this.options;
6188+
const {columns, raw, encoding} = this.options;
61896189
return {
61906190
...this.__infoDataSet(),
61916191
error: this.state.error,
61926192
header: columns === true,
61936193
index: this.state.record.length,
6194+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
61946195
};
61956196
}
61966197
__infoField(){

packages/csv-parse/dist/iife/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6171,11 +6171,11 @@ var csv_parse = (function (exports) {
61716171
return 0;
61726172
}
61736173
__error(msg){
6174-
const {skip_lines_with_error} = this.options;
6174+
const {encoding, raw, skip_lines_with_error} = this.options;
61756175
const err = typeof msg === 'string' ? new Error(msg) : msg;
61766176
if(skip_lines_with_error){
61776177
this.state.recordHasError = true;
6178-
this.emit('skip', err);
6178+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
61796179
return undefined;
61806180
}else {
61816181
return err;
@@ -6188,12 +6188,13 @@ var csv_parse = (function (exports) {
61886188
};
61896189
}
61906190
__infoRecord(){
6191-
const {columns} = this.options;
6191+
const {columns, raw, encoding} = this.options;
61926192
return {
61936193
...this.__infoDataSet(),
61946194
error: this.state.error,
61956195
header: columns === true,
61966196
index: this.state.record.length,
6197+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
61976198
};
61986199
}
61996200
__infoField(){

packages/csv-parse/dist/iife/sync.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6171,11 +6171,11 @@ var csv_parse_sync = (function (exports) {
61716171
return 0;
61726172
}
61736173
__error(msg){
6174-
const {skip_lines_with_error} = this.options;
6174+
const {encoding, raw, skip_lines_with_error} = this.options;
61756175
const err = typeof msg === 'string' ? new Error(msg) : msg;
61766176
if(skip_lines_with_error){
61776177
this.state.recordHasError = true;
6178-
this.emit('skip', err);
6178+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
61796179
return undefined;
61806180
}else {
61816181
return err;
@@ -6188,12 +6188,13 @@ var csv_parse_sync = (function (exports) {
61886188
};
61896189
}
61906190
__infoRecord(){
6191-
const {columns} = this.options;
6191+
const {columns, raw, encoding} = this.options;
61926192
return {
61936193
...this.__infoDataSet(),
61946194
error: this.state.error,
61956195
header: columns === true,
61966196
index: this.state.record.length,
6197+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
61976198
};
61986199
}
61996200
__infoField(){

packages/csv-parse/dist/umd/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6174,11 +6174,11 @@
61746174
return 0;
61756175
}
61766176
__error(msg){
6177-
const {skip_lines_with_error} = this.options;
6177+
const {encoding, raw, skip_lines_with_error} = this.options;
61786178
const err = typeof msg === 'string' ? new Error(msg) : msg;
61796179
if(skip_lines_with_error){
61806180
this.state.recordHasError = true;
6181-
this.emit('skip', err);
6181+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
61826182
return undefined;
61836183
}else {
61846184
return err;
@@ -6191,12 +6191,13 @@
61916191
};
61926192
}
61936193
__infoRecord(){
6194-
const {columns} = this.options;
6194+
const {columns, raw, encoding} = this.options;
61956195
return {
61966196
...this.__infoDataSet(),
61976197
error: this.state.error,
61986198
header: columns === true,
61996199
index: this.state.record.length,
6200+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
62006201
};
62016202
}
62026203
__infoField(){

packages/csv-parse/dist/umd/sync.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6174,11 +6174,11 @@
61746174
return 0;
61756175
}
61766176
__error(msg){
6177-
const {skip_lines_with_error} = this.options;
6177+
const {encoding, raw, skip_lines_with_error} = this.options;
61786178
const err = typeof msg === 'string' ? new Error(msg) : msg;
61796179
if(skip_lines_with_error){
61806180
this.state.recordHasError = true;
6181-
this.emit('skip', err);
6181+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
61826182
return undefined;
61836183
}else {
61846184
return err;
@@ -6191,12 +6191,13 @@
61916191
};
61926192
}
61936193
__infoRecord(){
6194-
const {columns} = this.options;
6194+
const {columns, raw, encoding} = this.options;
61956195
return {
61966196
...this.__infoDataSet(),
61976197
error: this.state.error,
61986198
header: columns === true,
61996199
index: this.state.record.length,
6200+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
62006201
};
62016202
}
62026203
__infoField(){

packages/csv-parse/lib/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,11 +1167,11 @@ class Parser extends Transform {
11671167
return 0;
11681168
}
11691169
__error(msg){
1170-
const {skip_lines_with_error} = this.options;
1170+
const {encoding, raw, skip_lines_with_error} = this.options;
11711171
const err = typeof msg === 'string' ? new Error(msg) : msg;
11721172
if(skip_lines_with_error){
11731173
this.state.recordHasError = true;
1174-
this.emit('skip', err);
1174+
this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
11751175
return undefined;
11761176
}else{
11771177
return err;
@@ -1184,12 +1184,13 @@ class Parser extends Transform {
11841184
};
11851185
}
11861186
__infoRecord(){
1187-
const {columns} = this.options;
1187+
const {columns, raw, encoding} = this.options;
11881188
return {
11891189
...this.__infoDataSet(),
11901190
error: this.state.error,
11911191
header: columns === true,
11921192
index: this.state.record.length,
1193+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined
11931194
};
11941195
}
11951196
__infoField(){

packages/csv-parse/samples/option.cast.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ assert.deepStrictEqual(records, [
2626
[ '2000-01-01T05:00:00.000Z', {
2727
bytes: 16, comment_lines: 0, empty_lines: 0, invalid_field_length: 0,
2828
lines: 1, records: 0, columns: false, error: undefined, header: false,
29-
index: 1, column: 1, quoting: false
29+
index: 1, column: 1, quoting: false, raw: undefined
3030
} ],
3131
[ '2050-11-27T05:00:00.000Z', {
3232
bytes: 35, comment_lines: 0, empty_lines: 0, invalid_field_length: 0,
3333
lines: 2, records: 1, columns: false, error: undefined, header: false,
34-
index: 1, column: 1, quoting: false
34+
index: 1, column: 1, quoting: false, raw: undefined
3535
} ]
3636
]);

0 commit comments

Comments
 (0)