Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeremiah-shaulov/deno_csv_file
CSV file reader and writer (seekable, sync/async)
https://github.com/jeremiah-shaulov/deno_csv_file
csv deno
Last synced: about 2 months ago
JSON representation
CSV file reader and writer (seekable, sync/async)
- Host: GitHub
- URL: https://github.com/jeremiah-shaulov/deno_csv_file
- Owner: jeremiah-shaulov
- Created: 2020-11-25T05:48:30.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-26T04:01:10.000Z (about 4 years ago)
- Last Synced: 2024-10-28T12:15:49.300Z (2 months ago)
- Topics: csv, deno
- Language: TypeScript
- Homepage: https://deno.land/x/csv_file
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# deno_csv_file
CSV file reader and writer for Deno (seekable, sync/async).[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/csv_file/mod.ts)
## Example
```typescript
import {CsvFile} from "https://deno.land/x/csv_file/mod.ts";// 1. Create a new file "/tmp/example-1.csv"
let csv = new CsvFile(await Deno.open('/tmp/example-1.csv', {read: true, write: true, create: true, truncate: true}));// 2. Write some records
await csv.writeRecord(['Day', 'Month', 'Year']);
await csv.writeRecord(['1', 'January', '2000']);
await csv.writeRecord(['2', 'January', '2000']);
await csv.writeRecord(['3', 'January', '2000']);// 3. Scroll to the beginning
await csv.seekRecord(0);// 4. Read the records back
for await (let record of csv)
{ console.log(record);
}// 5. Now try another way of reading records. So scroll to the beginning again
await csv.seekRecord(0);// 6. Read and remember a header row
await csv.readHeader();// 7. Read Map objects with column names taken from header
for await (let record of csv.maps())
{ console.log(record);
}// 8. Manually read record no. 2, and it's offset in file
await csv.seekRecord(2);
let file_offset = await csv.seek(0, Deno.SeekMode.Current);
let record = await csv.readRecord();
console.log(`Record no. 2 at ${file_offset}:`, record);// 9. Done
csv.close();
```Run like this:
```bash
deno run --allow-read --allow-write test.ts
```