You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/utils/dsv/base/parse/README.md
+15Lines changed: 15 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,8 @@ The constructor accepts the following `options`:
79
79
80
80
-**ltrim**: `boolean` indicating whether to trim leading whitepsace from field values. If `false`, the parser does not trim leading whitespace (e.g., `a, b, c` parses as `[ 'a', ' b', ' c' ]`). If `true`, the parser trims leading whitespace (e.g., `a, b, c` parses as `[ 'a', 'b', 'c' ]`). Default: `false`.
81
81
82
+
-**maxRows**: maximum number of records to process (excluding skipped lines). By default, the maximum number of records is unlimited.
83
+
82
84
-**newline**: character sequence separating rows. Default: `'\r\n'` (see [RFC 4180][rfc-4180]).
83
85
84
86
-**onClose**: callback to be invoked upon closing the parser. If a parser has partially processed a record upon close, the callback is invoked with the following arguments:
@@ -92,6 +94,7 @@ The constructor accepts the following `options`:
92
94
-**field**: field value.
93
95
-**row**: row number (zero-based).
94
96
-**col**: field (column) number (zero-based).
97
+
-**line**: line number (zero-based).
95
98
96
99
-**onComment**: callback to be invoked upon processing a commented line. The callback is invoked with the following arguments:
97
100
@@ -107,6 +110,7 @@ The constructor accepts the following `options`:
107
110
-**record**: an array-like object containing field values. If provided a `rowBuffer`, the `record` argument will be the **same** array-like object for each invocation.
108
111
-**row**: row number (zero-based).
109
112
-**ncols**: number of fields (columns).
113
+
-**line**: line number (zero-based).
110
114
111
115
If a parser is closed **before** fully processing the last record, the callback is invoked with field data for all fields which have been parsed. Any remaining field data is provided to the `onClose` callback. For example, if a parser has processed two fields and closes while attempting to process a third field, the parser invokes the `onRow` callback with field data for the first two fields and invokes the `onClose` callback with the partially processed data for the third field.
112
116
@@ -129,6 +133,17 @@ The constructor accepts the following `options`:
129
133
130
134
-**skip**: character sequence appearing at the beginning of a row which demarcates that the row content should be parsed as a skipped record. Default: `''`.
131
135
136
+
-**skipBlankRows**: `boolean` flag indicating whether to skip over rows which are either empty or containing only whitespace. Default: `false`.
137
+
138
+
-**skipRow**: callback whose return value indicates whether to skip over a row. The callback is invoked with the following arguments:
139
+
140
+
-**nrows**: number of processed rows (equivalent to the current row number).
141
+
-**line**: line number (zero-based).
142
+
143
+
If the callback returns a truthy value, the parser skips the row; otherwise, the parser attempts to process the row.
144
+
145
+
Note, however, that, even if the callback returns a falsy value, a row may still be skipped depending on the presence of a `skip` character sequence.
146
+
132
147
-**strict**: `boolean` flag indicating whether to raise an exception upon encountering invalid DSV. When `false`, instead of throwing an `Error` or invoking the `onError` callback, the parser invokes an `onWarn` callback with an `Error` object specifying the encountered error. Default: `true`.
133
148
134
149
-**trimComment**: `boolean` flag indicating whether to trim leading whitespace in commented lines. Default: `true`.
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/utils/dsv/base/parse/lib/defaults.js
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,9 @@ function defaults() {
66
66
// Flag indicating whether to trim leading whitespace from field values. If `false`, leading whitespace is not trimmed (e.g., `a, b, c` parses as `[ 'a', ' b', ' c' ]`). If `true`, leading whitespace is trimmed (e.g., `a, b, c` parses as `[ 'a', 'b', 'c' ]`).
67
67
'ltrim': false,
68
68
69
+
// Maximum number of records to process.
70
+
'maxRows': 1e308,
71
+
69
72
// Character sequence separating rows.
70
73
'newline': '\r\n',
71
74
@@ -105,6 +108,12 @@ function defaults() {
105
108
// Character sequence appearing at the beginning of a row which demarcates that the row content should be skipped.
106
109
'skip': '',
107
110
111
+
// Flag indicating whether to skip over rows which are either empty or containing only whitespace.
112
+
'skipBlankRows': false,
113
+
114
+
// Callback whose return value indicates whether to skip over a row.
115
+
'skipRow': null,
116
+
108
117
// Flag indicating whether to raise an exception upon encountering invalid DSV.
// Increment the counter for how many lines have been processed:
522
546
this._line+=1;
@@ -572,13 +596,13 @@ setReadOnly( Parser.prototype, '_createException', function createException( nam
572
596
573
597
switch(name){
574
598
case'INVALID_CLOSING_QUOTE':
575
-
err=newError(format('unexpected error. Encountered an invalid record. Field %d on line %d contains a closing quote which is not immediately followed by a delimiter or newline.',this._col+1,this._line+1));
599
+
err=newError(format('unexpected error. Encountered an invalid record. Field %d on line %d contains a closing quote which is not immediately followed by a delimiter or newline.',this._col,this._line));
576
600
break;
577
601
case'INVALID_ESCAPE':
578
-
err=newError(format('unexpected error. Encountered an invalid record. Field %d on line %d contains an escape sequence which is not immediately followed by a special character sequence.',this._col+1,this._line+1));
602
+
err=newError(format('unexpected error. Encountered an invalid record. Field %d on line %d contains an escape sequence which is not immediately followed by a special character sequence.',this._col,this._line));
579
603
break;
580
604
case'INVALID_QUOTED_ESCAPE':
581
-
err=newError(format('unexpected error. Encountered an invalid record. Field %d on line %d contains an escape sequence within a quoted field which is not immediately followed by a quote sequence.',this._col+1,this._line+1));
605
+
err=newError(format('unexpected error. Encountered an invalid record. Field %d on line %d contains an escape sequence within a quoted field which is not immediately followed by a quote sequence.',this._col,this._line));
582
606
break;
583
607
case'CLOSED':
584
608
err=newError('invalid operation. Parser is unable to parse new chunks, as the parser has been closed. To parse new chunks, create a new parser instance.');
0 commit comments