Download Reactive-Resume/libs/utils/src/namespaces/csv.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 745 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/Reactive-Resume/libs/utils/src/namespaces/csv.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/Reactive-Resume/libs/utils/src/namespaces/csv.ts
-
curl -L -o csv.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/Reactive-Resume/libs/utils/src/namespaces/csv.ts
745 Bytes
| import Papa from "papaparse"; | |
| import type { Json } from "./types"; | |
| export const parseCSV = async (string: string) => { | |
| return new Promise<Json[]>((resolve, reject) => { | |
| Papa.parse(string, { | |
| header: true, | |
| skipEmptyLines: true, | |
| complete: (results) => { | |
| resolve(results.data as Json[]); | |
| }, | |
| error: (error: Error) => { | |
| reject(error); | |
| }, | |
| }); | |
| }); | |
| }; | |
| /** | |
| * Parser for cases when we receive an array like structure f.e. in the LinkedIn Profile.csv import | |
| * @param csvEntry array-like entry such as [TAG:https://some.link,TAG:https://someother.link] | |
| * @returns | |
| */ | |
| export const parseArrayLikeCSVEntry = (csvEntry: string) => | |
| csvEntry.replace(/^\[/, "").replace(/$]/, "").split(","); | |