Skip to content

Commit

Permalink
fix(csv-sample): prevent topKey exception (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon committed Apr 15, 2022
1 parent 9fe4b5d commit 34e3dcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/csv-sample/src/index.ts
Expand Up @@ -74,7 +74,7 @@ const guessColumnsTypes = (samples: Sample[], onProgress: onProgressFunction) =>
const detectedType = topKey(detectedTypes, "type");
return {
...sample,
type: detectedType,
type: detectedType || "unknown",
};
}
return {
Expand Down
7 changes: 4 additions & 3 deletions packages/csv-sample/src/utils.ts
Expand Up @@ -22,7 +22,7 @@ const getRandomItems = (arr: any[], n: number) => {
};

// extract the most present value for a given list of records and a given key
export const topKey = (arr: Row[], key: string): string => {
export const topKey = (arr: Row[], key: string): string | undefined => {
if (arr.length === 1) {
return arr[0][key];
}
Expand All @@ -41,8 +41,9 @@ export const topKey = (arr: Row[], key: string): string => {
return a[1] - b[1];
})
.reverse();

return totals[0][0];
if (totals.length && totals[0].length) {
return totals[0][0];
}
};

export const wait = (args: any) =>
Expand Down

0 comments on commit 34e3dcc

Please sign in to comment.