Skip to content

Commit 9fffd50

Browse files
committed
refactor(csv-parse)!: rename relax to relax_quotes
1 parent 6eed22a commit 9fffd50

16 files changed

+145
-143
lines changed

packages/csv-parse/ROADMAP.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ We invite you to join and contribute but create an issue before engaging any wor
66

77
* `skip_lines_with_empty_values`: rename to skip_records_with_empty_values (easy)
88
* `skip_lines_with_error`: rename to skip_records_with_error (easy)
9-
* `relax`: rename to relax_quotes_when_unquoted (easy)
109
* `max_comment_size`: new option (medium)
1110
* promise: new API module (medium)
1211
* errors: finish normalisation of all errors (easy)

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -5388,7 +5388,7 @@ class Parser extends Transform {
53885388
// Normalize option `record_delimiter`
53895389
if(options.record_delimiter === undefined){
53905390
options.record_delimiter = [];
5391-
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter) ){
5391+
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter)){
53925392
if(options.record_delimiter.length === 0){
53935393
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
53945394
'Invalid option `record_delimiter`:',
@@ -5405,7 +5405,7 @@ class Parser extends Transform {
54055405
], options);
54065406
}
54075407
options.record_delimiter = options.record_delimiter.map(function(rd, i){
5408-
if(typeof rd !== 'string' && ! isBuffer(rd) ){
5408+
if(typeof rd !== 'string' && ! isBuffer(rd)){
54095409
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
54105410
'Invalid option `record_delimiter`:',
54115411
'value must be a string, a buffer or array of string|buffer',
@@ -5425,12 +5425,6 @@ class Parser extends Transform {
54255425
}
54265426
return rd;
54275427
});
5428-
// Normalize option `relax`
5429-
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
5430-
options.relax = false;
5431-
}else {
5432-
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
5433-
}
54345428
// Normalize option `relax_column_count`
54355429
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
54365430
options.relax_column_count = false;
@@ -5447,6 +5441,12 @@ class Parser extends Transform {
54475441
}else {
54485442
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
54495443
}
5444+
// Normalize option `relax_quotes`
5445+
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
5446+
options.relax_quotes = false;
5447+
}else {
5448+
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
5449+
}
54505450
// Normalize option `skip_empty_lines`
54515451
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
54525452
options.skip_empty_lines = false;
@@ -5589,7 +5589,7 @@ class Parser extends Transform {
55895589
}
55905590
// Central parser implementation
55915591
__parse(nextBuf, end){
5592-
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
5592+
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
55935593
let {record_delimiter} = this.options;
55945594
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
55955595
let buf;
@@ -5702,7 +5702,7 @@ class Parser extends Transform {
57025702
this.state.wasQuoting = true;
57035703
pos += quote.length - 1;
57045704
continue;
5705-
}else if(relax === false){
5705+
}else if(relax_quotes === false){
57065706
const err = this.__error(
57075707
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
57085708
'Invalid Closing Quote:',
@@ -5721,8 +5721,8 @@ class Parser extends Transform {
57215721
}
57225722
}else {
57235723
if(this.state.field.length !== 0){
5724-
// In relax mode, treat opening quote preceded by chrs as regular
5725-
if(relax === false){
5724+
// In relax_quotes mode, treat opening quote preceded by chrs as regular
5725+
if(relax_quotes === false){
57265726
const err = this.__error(
57275727
new CsvError('INVALID_OPENING_QUOTE', [
57285728
'Invalid Opening Quote:',

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ export interface Options {
146146
* Generate two properties raw and row where raw is the original CSV row content and row is the parsed array or object.
147147
*/
148148
raw?: boolean;
149-
/**
150-
* Preserve quotes inside unquoted field.
151-
*/
152-
relax?: boolean;
153149
/**
154150
* Discard inconsistent columns count, default to false.
155151
*/
@@ -165,6 +161,11 @@ export interface Options {
165161
*/
166162
relax_column_count_more?: boolean;
167163
relaxColumnCountMore?: boolean;
164+
/**
165+
* Preserve quotes inside unquoted field.
166+
*/
167+
relax_quotes?: boolean;
168+
relaxQuotes?: boolean;
168169
/**
169170
* One or multiple characters used to delimit record rows; defaults to auto discovery if not provided.
170171
* Supported auto discovery method are Linux ("\n"), Apple ("\r") and Windows ("\r\n") row delimiters.

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -5425,12 +5425,6 @@ class Parser extends Transform {
54255425
}
54265426
return rd;
54275427
});
5428-
// Normalize option `relax`
5429-
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
5430-
options.relax = false;
5431-
}else {
5432-
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
5433-
}
54345428
// Normalize option `relax_column_count`
54355429
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
54365430
options.relax_column_count = false;
@@ -5447,6 +5441,12 @@ class Parser extends Transform {
54475441
}else {
54485442
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
54495443
}
5444+
// Normalize option `relax_quotes`
5445+
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
5446+
options.relax_quotes = false;
5447+
}else {
5448+
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
5449+
}
54505450
// Normalize option `skip_empty_lines`
54515451
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
54525452
options.skip_empty_lines = false;
@@ -5589,7 +5589,7 @@ class Parser extends Transform {
55895589
}
55905590
// Central parser implementation
55915591
__parse(nextBuf, end){
5592-
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
5592+
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
55935593
let {record_delimiter} = this.options;
55945594
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
55955595
let buf;
@@ -5702,7 +5702,7 @@ class Parser extends Transform {
57025702
this.state.wasQuoting = true;
57035703
pos += quote.length - 1;
57045704
continue;
5705-
}else if(relax === false){
5705+
}else if(relax_quotes === false){
57065706
const err = this.__error(
57075707
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
57085708
'Invalid Closing Quote:',
@@ -5721,8 +5721,8 @@ class Parser extends Transform {
57215721
}
57225722
}else {
57235723
if(this.state.field.length !== 0){
5724-
// In relax mode, treat opening quote preceded by chrs as regular
5725-
if(relax === false){
5724+
// In relax_quotes mode, treat opening quote preceded by chrs as regular
5725+
if(relax_quotes === false){
57265726
const err = this.__error(
57275727
new CsvError('INVALID_OPENING_QUOTE', [
57285728
'Invalid Opening Quote:',

packages/csv-parse/dist/esm/index.d.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ export interface Options {
146146
* Generate two properties raw and row where raw is the original CSV row content and row is the parsed array or object.
147147
*/
148148
raw?: boolean;
149-
/**
150-
* Preserve quotes inside unquoted field.
151-
*/
152-
relax?: boolean;
153149
/**
154150
* Discard inconsistent columns count, default to false.
155151
*/
@@ -165,6 +161,11 @@ export interface Options {
165161
*/
166162
relax_column_count_more?: boolean;
167163
relaxColumnCountMore?: boolean;
164+
/**
165+
* Preserve quotes inside unquoted field.
166+
*/
167+
relax_quotes?: boolean;
168+
relaxQuotes?: boolean;
168169
/**
169170
* One or multiple characters used to delimit record rows; defaults to auto discovery if not provided.
170171
* Supported auto discovery method are Linux ("\n"), Apple ("\r") and Windows ("\r\n") row delimiters.

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -5384,7 +5384,7 @@ class Parser extends Transform {
53845384
// Normalize option `record_delimiter`
53855385
if(options.record_delimiter === undefined){
53865386
options.record_delimiter = [];
5387-
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter) ){
5387+
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter)){
53885388
if(options.record_delimiter.length === 0){
53895389
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
53905390
'Invalid option `record_delimiter`:',
@@ -5401,7 +5401,7 @@ class Parser extends Transform {
54015401
], options);
54025402
}
54035403
options.record_delimiter = options.record_delimiter.map(function(rd, i){
5404-
if(typeof rd !== 'string' && ! isBuffer(rd) ){
5404+
if(typeof rd !== 'string' && ! isBuffer(rd)){
54055405
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
54065406
'Invalid option `record_delimiter`:',
54075407
'value must be a string, a buffer or array of string|buffer',
@@ -5421,12 +5421,6 @@ class Parser extends Transform {
54215421
}
54225422
return rd;
54235423
});
5424-
// Normalize option `relax`
5425-
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
5426-
options.relax = false;
5427-
}else {
5428-
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
5429-
}
54305424
// Normalize option `relax_column_count`
54315425
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
54325426
options.relax_column_count = false;
@@ -5443,6 +5437,12 @@ class Parser extends Transform {
54435437
}else {
54445438
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
54455439
}
5440+
// Normalize option `relax_quotes`
5441+
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
5442+
options.relax_quotes = false;
5443+
}else {
5444+
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
5445+
}
54465446
// Normalize option `skip_empty_lines`
54475447
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
54485448
options.skip_empty_lines = false;
@@ -5585,7 +5585,7 @@ class Parser extends Transform {
55855585
}
55865586
// Central parser implementation
55875587
__parse(nextBuf, end){
5588-
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
5588+
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
55895589
let {record_delimiter} = this.options;
55905590
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
55915591
let buf;
@@ -5698,7 +5698,7 @@ class Parser extends Transform {
56985698
this.state.wasQuoting = true;
56995699
pos += quote.length - 1;
57005700
continue;
5701-
}else if(relax === false){
5701+
}else if(relax_quotes === false){
57025702
const err = this.__error(
57035703
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
57045704
'Invalid Closing Quote:',
@@ -5717,8 +5717,8 @@ class Parser extends Transform {
57175717
}
57185718
}else {
57195719
if(this.state.field.length !== 0){
5720-
// In relax mode, treat opening quote preceded by chrs as regular
5721-
if(relax === false){
5720+
// In relax_quotes mode, treat opening quote preceded by chrs as regular
5721+
if(relax_quotes === false){
57225722
const err = this.__error(
57235723
new CsvError('INVALID_OPENING_QUOTE', [
57245724
'Invalid Opening Quote:',

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -5421,12 +5421,6 @@ class Parser extends Transform {
54215421
}
54225422
return rd;
54235423
});
5424-
// Normalize option `relax`
5425-
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
5426-
options.relax = false;
5427-
}else {
5428-
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
5429-
}
54305424
// Normalize option `relax_column_count`
54315425
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
54325426
options.relax_column_count = false;
@@ -5443,6 +5437,12 @@ class Parser extends Transform {
54435437
}else {
54445438
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
54455439
}
5440+
// Normalize option `relax_quotes`
5441+
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
5442+
options.relax_quotes = false;
5443+
}else {
5444+
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
5445+
}
54465446
// Normalize option `skip_empty_lines`
54475447
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
54485448
options.skip_empty_lines = false;
@@ -5585,7 +5585,7 @@ class Parser extends Transform {
55855585
}
55865586
// Central parser implementation
55875587
__parse(nextBuf, end){
5588-
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
5588+
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
55895589
let {record_delimiter} = this.options;
55905590
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
55915591
let buf;
@@ -5698,7 +5698,7 @@ class Parser extends Transform {
56985698
this.state.wasQuoting = true;
56995699
pos += quote.length - 1;
57005700
continue;
5701-
}else if(relax === false){
5701+
}else if(relax_quotes === false){
57025702
const err = this.__error(
57035703
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
57045704
'Invalid Closing Quote:',
@@ -5717,8 +5717,8 @@ class Parser extends Transform {
57175717
}
57185718
}else {
57195719
if(this.state.field.length !== 0){
5720-
// In relax mode, treat opening quote preceded by chrs as regular
5721-
if(relax === false){
5720+
// In relax_quotes mode, treat opening quote preceded by chrs as regular
5721+
if(relax_quotes === false){
57225722
const err = this.__error(
57235723
new CsvError('INVALID_OPENING_QUOTE', [
57245724
'Invalid Opening Quote:',

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -5387,7 +5387,7 @@ var csv_parse = (function (exports) {
53875387
// Normalize option `record_delimiter`
53885388
if(options.record_delimiter === undefined){
53895389
options.record_delimiter = [];
5390-
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter) ){
5390+
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter)){
53915391
if(options.record_delimiter.length === 0){
53925392
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
53935393
'Invalid option `record_delimiter`:',
@@ -5404,7 +5404,7 @@ var csv_parse = (function (exports) {
54045404
], options);
54055405
}
54065406
options.record_delimiter = options.record_delimiter.map(function(rd, i){
5407-
if(typeof rd !== 'string' && ! isBuffer(rd) ){
5407+
if(typeof rd !== 'string' && ! isBuffer(rd)){
54085408
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
54095409
'Invalid option `record_delimiter`:',
54105410
'value must be a string, a buffer or array of string|buffer',
@@ -5424,12 +5424,6 @@ var csv_parse = (function (exports) {
54245424
}
54255425
return rd;
54265426
});
5427-
// Normalize option `relax`
5428-
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
5429-
options.relax = false;
5430-
}else {
5431-
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
5432-
}
54335427
// Normalize option `relax_column_count`
54345428
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
54355429
options.relax_column_count = false;
@@ -5446,6 +5440,12 @@ var csv_parse = (function (exports) {
54465440
}else {
54475441
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
54485442
}
5443+
// Normalize option `relax_quotes`
5444+
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
5445+
options.relax_quotes = false;
5446+
}else {
5447+
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
5448+
}
54495449
// Normalize option `skip_empty_lines`
54505450
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
54515451
options.skip_empty_lines = false;
@@ -5588,7 +5588,7 @@ var csv_parse = (function (exports) {
55885588
}
55895589
// Central parser implementation
55905590
__parse(nextBuf, end){
5591-
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
5591+
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
55925592
let {record_delimiter} = this.options;
55935593
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
55945594
let buf;
@@ -5701,7 +5701,7 @@ var csv_parse = (function (exports) {
57015701
this.state.wasQuoting = true;
57025702
pos += quote.length - 1;
57035703
continue;
5704-
}else if(relax === false){
5704+
}else if(relax_quotes === false){
57055705
const err = this.__error(
57065706
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
57075707
'Invalid Closing Quote:',
@@ -5720,8 +5720,8 @@ var csv_parse = (function (exports) {
57205720
}
57215721
}else {
57225722
if(this.state.field.length !== 0){
5723-
// In relax mode, treat opening quote preceded by chrs as regular
5724-
if(relax === false){
5723+
// In relax_quotes mode, treat opening quote preceded by chrs as regular
5724+
if(relax_quotes === false){
57255725
const err = this.__error(
57265726
new CsvError('INVALID_OPENING_QUOTE', [
57275727
'Invalid Opening Quote:',

0 commit comments

Comments
 (0)