Skip to content

Commit

Permalink
refactor(csv-parse)!: rename relax to relax_quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 6, 2021
1 parent 6eed22a commit 9fffd50
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 143 deletions.
1 change: 0 additions & 1 deletion packages/csv-parse/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ We invite you to join and contribute but create an issue before engaging any wor

* `skip_lines_with_empty_values`: rename to skip_records_with_empty_values (easy)
* `skip_lines_with_error`: rename to skip_records_with_error (easy)
* `relax`: rename to relax_quotes_when_unquoted (easy)
* `max_comment_size`: new option (medium)
* promise: new API module (medium)
* errors: finish normalisation of all errors (easy)
Expand Down
24 changes: 12 additions & 12 deletions packages/csv-parse/dist/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5388,7 +5388,7 @@ class Parser extends Transform {
// Normalize option `record_delimiter`
if(options.record_delimiter === undefined){
options.record_delimiter = [];
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter) ){
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter)){
if(options.record_delimiter.length === 0){
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
'Invalid option `record_delimiter`:',
Expand All @@ -5405,7 +5405,7 @@ class Parser extends Transform {
], options);
}
options.record_delimiter = options.record_delimiter.map(function(rd, i){
if(typeof rd !== 'string' && ! isBuffer(rd) ){
if(typeof rd !== 'string' && ! isBuffer(rd)){
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
'Invalid option `record_delimiter`:',
'value must be a string, a buffer or array of string|buffer',
Expand All @@ -5425,12 +5425,6 @@ class Parser extends Transform {
}
return rd;
});
// Normalize option `relax`
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
options.relax = false;
}else {
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
}
// Normalize option `relax_column_count`
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
options.relax_column_count = false;
Expand All @@ -5447,6 +5441,12 @@ class Parser extends Transform {
}else {
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
}
// Normalize option `relax_quotes`
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
options.relax_quotes = false;
}else {
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
}
// Normalize option `skip_empty_lines`
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
options.skip_empty_lines = false;
Expand Down Expand Up @@ -5589,7 +5589,7 @@ class Parser extends Transform {
}
// Central parser implementation
__parse(nextBuf, end){
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
let {record_delimiter} = this.options;
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
let buf;
Expand Down Expand Up @@ -5702,7 +5702,7 @@ class Parser extends Transform {
this.state.wasQuoting = true;
pos += quote.length - 1;
continue;
}else if(relax === false){
}else if(relax_quotes === false){
const err = this.__error(
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
'Invalid Closing Quote:',
Expand All @@ -5721,8 +5721,8 @@ class Parser extends Transform {
}
}else {
if(this.state.field.length !== 0){
// In relax mode, treat opening quote preceded by chrs as regular
if(relax === false){
// In relax_quotes mode, treat opening quote preceded by chrs as regular
if(relax_quotes === false){
const err = this.__error(
new CsvError('INVALID_OPENING_QUOTE', [
'Invalid Opening Quote:',
Expand Down
9 changes: 5 additions & 4 deletions packages/csv-parse/dist/cjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ export interface Options {
* Generate two properties raw and row where raw is the original CSV row content and row is the parsed array or object.
*/
raw?: boolean;
/**
* Preserve quotes inside unquoted field.
*/
relax?: boolean;
/**
* Discard inconsistent columns count, default to false.
*/
Expand All @@ -165,6 +161,11 @@ export interface Options {
*/
relax_column_count_more?: boolean;
relaxColumnCountMore?: boolean;
/**
* Preserve quotes inside unquoted field.
*/
relax_quotes?: boolean;
relaxQuotes?: boolean;
/**
* One or multiple characters used to delimit record rows; defaults to auto discovery if not provided.
* Supported auto discovery method are Linux ("\n"), Apple ("\r") and Windows ("\r\n") row delimiters.
Expand Down
20 changes: 10 additions & 10 deletions packages/csv-parse/dist/cjs/sync.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5425,12 +5425,6 @@ class Parser extends Transform {
}
return rd;
});
// Normalize option `relax`
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
options.relax = false;
}else {
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
}
// Normalize option `relax_column_count`
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
options.relax_column_count = false;
Expand All @@ -5447,6 +5441,12 @@ class Parser extends Transform {
}else {
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
}
// Normalize option `relax_quotes`
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
options.relax_quotes = false;
}else {
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
}
// Normalize option `skip_empty_lines`
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
options.skip_empty_lines = false;
Expand Down Expand Up @@ -5589,7 +5589,7 @@ class Parser extends Transform {
}
// Central parser implementation
__parse(nextBuf, end){
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
let {record_delimiter} = this.options;
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
let buf;
Expand Down Expand Up @@ -5702,7 +5702,7 @@ class Parser extends Transform {
this.state.wasQuoting = true;
pos += quote.length - 1;
continue;
}else if(relax === false){
}else if(relax_quotes === false){
const err = this.__error(
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
'Invalid Closing Quote:',
Expand All @@ -5721,8 +5721,8 @@ class Parser extends Transform {
}
}else {
if(this.state.field.length !== 0){
// In relax mode, treat opening quote preceded by chrs as regular
if(relax === false){
// In relax_quotes mode, treat opening quote preceded by chrs as regular
if(relax_quotes === false){
const err = this.__error(
new CsvError('INVALID_OPENING_QUOTE', [
'Invalid Opening Quote:',
Expand Down
9 changes: 5 additions & 4 deletions packages/csv-parse/dist/esm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ export interface Options {
* Generate two properties raw and row where raw is the original CSV row content and row is the parsed array or object.
*/
raw?: boolean;
/**
* Preserve quotes inside unquoted field.
*/
relax?: boolean;
/**
* Discard inconsistent columns count, default to false.
*/
Expand All @@ -165,6 +161,11 @@ export interface Options {
*/
relax_column_count_more?: boolean;
relaxColumnCountMore?: boolean;
/**
* Preserve quotes inside unquoted field.
*/
relax_quotes?: boolean;
relaxQuotes?: boolean;
/**
* One or multiple characters used to delimit record rows; defaults to auto discovery if not provided.
* Supported auto discovery method are Linux ("\n"), Apple ("\r") and Windows ("\r\n") row delimiters.
Expand Down
24 changes: 12 additions & 12 deletions packages/csv-parse/dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5384,7 +5384,7 @@ class Parser extends Transform {
// Normalize option `record_delimiter`
if(options.record_delimiter === undefined){
options.record_delimiter = [];
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter) ){
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter)){
if(options.record_delimiter.length === 0){
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
'Invalid option `record_delimiter`:',
Expand All @@ -5401,7 +5401,7 @@ class Parser extends Transform {
], options);
}
options.record_delimiter = options.record_delimiter.map(function(rd, i){
if(typeof rd !== 'string' && ! isBuffer(rd) ){
if(typeof rd !== 'string' && ! isBuffer(rd)){
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
'Invalid option `record_delimiter`:',
'value must be a string, a buffer or array of string|buffer',
Expand All @@ -5421,12 +5421,6 @@ class Parser extends Transform {
}
return rd;
});
// Normalize option `relax`
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
options.relax = false;
}else {
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
}
// Normalize option `relax_column_count`
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
options.relax_column_count = false;
Expand All @@ -5443,6 +5437,12 @@ class Parser extends Transform {
}else {
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
}
// Normalize option `relax_quotes`
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
options.relax_quotes = false;
}else {
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
}
// Normalize option `skip_empty_lines`
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
options.skip_empty_lines = false;
Expand Down Expand Up @@ -5585,7 +5585,7 @@ class Parser extends Transform {
}
// Central parser implementation
__parse(nextBuf, end){
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
let {record_delimiter} = this.options;
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
let buf;
Expand Down Expand Up @@ -5698,7 +5698,7 @@ class Parser extends Transform {
this.state.wasQuoting = true;
pos += quote.length - 1;
continue;
}else if(relax === false){
}else if(relax_quotes === false){
const err = this.__error(
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
'Invalid Closing Quote:',
Expand All @@ -5717,8 +5717,8 @@ class Parser extends Transform {
}
}else {
if(this.state.field.length !== 0){
// In relax mode, treat opening quote preceded by chrs as regular
if(relax === false){
// In relax_quotes mode, treat opening quote preceded by chrs as regular
if(relax_quotes === false){
const err = this.__error(
new CsvError('INVALID_OPENING_QUOTE', [
'Invalid Opening Quote:',
Expand Down
20 changes: 10 additions & 10 deletions packages/csv-parse/dist/esm/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5421,12 +5421,6 @@ class Parser extends Transform {
}
return rd;
});
// Normalize option `relax`
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
options.relax = false;
}else {
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
}
// Normalize option `relax_column_count`
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
options.relax_column_count = false;
Expand All @@ -5443,6 +5437,12 @@ class Parser extends Transform {
}else {
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
}
// Normalize option `relax_quotes`
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
options.relax_quotes = false;
}else {
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
}
// Normalize option `skip_empty_lines`
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
options.skip_empty_lines = false;
Expand Down Expand Up @@ -5585,7 +5585,7 @@ class Parser extends Transform {
}
// Central parser implementation
__parse(nextBuf, end){
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
let {record_delimiter} = this.options;
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
let buf;
Expand Down Expand Up @@ -5698,7 +5698,7 @@ class Parser extends Transform {
this.state.wasQuoting = true;
pos += quote.length - 1;
continue;
}else if(relax === false){
}else if(relax_quotes === false){
const err = this.__error(
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
'Invalid Closing Quote:',
Expand All @@ -5717,8 +5717,8 @@ class Parser extends Transform {
}
}else {
if(this.state.field.length !== 0){
// In relax mode, treat opening quote preceded by chrs as regular
if(relax === false){
// In relax_quotes mode, treat opening quote preceded by chrs as regular
if(relax_quotes === false){
const err = this.__error(
new CsvError('INVALID_OPENING_QUOTE', [
'Invalid Opening Quote:',
Expand Down
24 changes: 12 additions & 12 deletions packages/csv-parse/dist/iife/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5387,7 +5387,7 @@ var csv_parse = (function (exports) {
// Normalize option `record_delimiter`
if(options.record_delimiter === undefined){
options.record_delimiter = [];
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter) ){
}else if(typeof options.record_delimiter === 'string' || isBuffer(options.record_delimiter)){
if(options.record_delimiter.length === 0){
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
'Invalid option `record_delimiter`:',
Expand All @@ -5404,7 +5404,7 @@ var csv_parse = (function (exports) {
], options);
}
options.record_delimiter = options.record_delimiter.map(function(rd, i){
if(typeof rd !== 'string' && ! isBuffer(rd) ){
if(typeof rd !== 'string' && ! isBuffer(rd)){
throw new CsvError('CSV_INVALID_OPTION_RECORD_DELIMITER', [
'Invalid option `record_delimiter`:',
'value must be a string, a buffer or array of string|buffer',
Expand All @@ -5424,12 +5424,6 @@ var csv_parse = (function (exports) {
}
return rd;
});
// Normalize option `relax`
if(typeof options.relax === 'boolean');else if(options.relax === undefined || options.relax === null){
options.relax = false;
}else {
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`);
}
// Normalize option `relax_column_count`
if(typeof options.relax_column_count === 'boolean');else if(options.relax_column_count === undefined || options.relax_column_count === null){
options.relax_column_count = false;
Expand All @@ -5446,6 +5440,12 @@ var csv_parse = (function (exports) {
}else {
throw new Error(`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`);
}
// Normalize option `relax_quotes`
if(typeof options.relax_quotes === 'boolean');else if(options.relax_quotes === undefined || options.relax_quotes === null){
options.relax_quotes = false;
}else {
throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`);
}
// Normalize option `skip_empty_lines`
if(typeof options.skip_empty_lines === 'boolean');else if(options.skip_empty_lines === undefined || options.skip_empty_lines === null){
options.skip_empty_lines = false;
Expand Down Expand Up @@ -5588,7 +5588,7 @@ var csv_parse = (function (exports) {
}
// Central parser implementation
__parse(nextBuf, end){
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options;
const {bom, comment, escape, from_line, ltrim, max_record_size, quote, raw, relax_quotes, rtrim, skip_empty_lines, to, to_line} = this.options;
let {record_delimiter} = this.options;
const {bomSkipped, previousBuf, rawBuffer, escapeIsQuote} = this.state;
let buf;
Expand Down Expand Up @@ -5701,7 +5701,7 @@ var csv_parse = (function (exports) {
this.state.wasQuoting = true;
pos += quote.length - 1;
continue;
}else if(relax === false){
}else if(relax_quotes === false){
const err = this.__error(
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
'Invalid Closing Quote:',
Expand All @@ -5720,8 +5720,8 @@ var csv_parse = (function (exports) {
}
}else {
if(this.state.field.length !== 0){
// In relax mode, treat opening quote preceded by chrs as regular
if(relax === false){
// In relax_quotes mode, treat opening quote preceded by chrs as regular
if(relax_quotes === false){
const err = this.__error(
new CsvError('INVALID_OPENING_QUOTE', [
'Invalid Opening Quote:',
Expand Down
Loading

0 comments on commit 9fffd50

Please sign in to comment.