Skip to content

Commit

Permalink
fix: handle trimming null/undefined header values
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo Ephraim committed Sep 7, 2023
1 parent 867bb63 commit 3ef8fcf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/GoogleSpreadsheetWorksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class GoogleSpreadsheetWorksheet {
if (!rows) {
throw new Error('No values in the header row - fill the first row with header values before trying to interact with rows');
}
this._headerValues = _.map(rows[0], (header) => header.trim());
this._headerValues = _.map(rows[0], (header) => header?.trim());
if (!_.compact(this.headerValues).length) {
throw new Error('All your header cells are blank - fill the first row with header values before trying to interact with rows');
}
Expand All @@ -357,7 +357,7 @@ export class GoogleSpreadsheetWorksheet {
if (headerValues.length > this.columnCount) {
throw new Error(`Sheet is not large enough to fit ${headerValues.length} columns. Resize the sheet first.`);
}
const trimmedHeaderValues = _.map(headerValues, (h) => h.trim());
const trimmedHeaderValues = _.map(headerValues, (h) => h?.trim());
checkForDuplicateHeaders(trimmedHeaderValues);

if (!_.compact(trimmedHeaderValues).length) {
Expand Down

0 comments on commit 3ef8fcf

Please sign in to comment.