-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rm type cast, abstract papa parse, use axios
- Loading branch information
1 parent
9df257d
commit 78f1db6
Showing
2 changed files
with
44 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Papa from "papaparse" | ||
|
||
export default function promisifyPapaParse<T>(content: string) { | ||
return new Promise<T>((resolve, reject) => { | ||
Papa.parse(content, { | ||
header: true, | ||
complete(results) { | ||
// validate the csv | ||
if (!results.data) { | ||
reject(new Error("Failed to parse csv")) | ||
} | ||
resolve(results.data as T) | ||
}, | ||
error(error: unknown) { | ||
reject(error) | ||
}, | ||
}) | ||
}) | ||
} |