Giter Club home page Giter Club logo

deno_csv_file's Introduction

deno_csv_file

CSV file reader and writer for Deno (seekable, sync/async).

deno doc

Example

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:

deno run --allow-read --allow-write test.ts

deno_csv_file's People

Contributors

jeremiah-shaulov avatar

Stargazers

TAn avatar

Watchers

TAn avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.