Skip to content

Commit

Permalink
feat: Added greedy option for skipEmptyLines to handle blank lines an… (
Browse files Browse the repository at this point in the history
#932)

Description:
The skipEmptyLines option in Papa Parse was previously set to true,
which only skips fully blank lines. However, lines containing just
commas (e.g., ,,,,, ,,,,,) were not being handled correctly and would
still be parsed as valid, non-empty lines, causing issues in CSV parsing
and was causing empty records.

Changes Made:
Added the 'greedy' option to the skipEmptyLines configuration.
This update ensures that both blank lines and lines containing only
commas (e.g., ,,,,, ,,,,,) are treated as empty and skipped during
parsing, improving how CSV files are handled.
  • Loading branch information
chavda-bhavik authored Jan 31, 2025
2 parents f2d768b + 38bd803 commit c80fc6b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class BaseReview {
validRecords = 0;
Papa.parse(csvFileStream, {
dynamicTyping: false,
skipEmptyLines: true,
skipEmptyLines: 'greedy',
step: (results: Papa.ParseStepResult<any>) => {
totalRecords++;
const record = results.data;
Expand Down Expand Up @@ -593,7 +593,7 @@ export class BaseReview {

Papa.parse(csvFileStream, {
dynamicTyping: false,
skipEmptyLines: true,
skipEmptyLines: 'greedy',
step: (results: Papa.ParseStepResult<any>) => {
recordsCount++;
const record = results.data;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/shared/services/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class CSVFileService2 {
parse(fileContent, {
...(options || {}),
dynamicTyping: false,
skipEmptyLines: true,
skipEmptyLines: 'greedy',
step: function (results) {
rows++;
if (Array.isArray(results.data)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class GetPreviewRows {
return new Promise((resolve, reject) => {
Papa.parse(csvFileStream, {
dynamicTyping: false,
skipEmptyLines: true,
skipEmptyLines: 'greedy',
preview: 15,
complete({ data }) {
resolve(data);
Expand Down

0 comments on commit c80fc6b

Please sign in to comment.