{"id":13485151,"url":"https://github.com/vslinko/deno-csv","last_synced_at":"2025-04-12T11:51:26.904Z","repository":{"id":43692611,"uuid":"264042904","full_name":"vslinko/deno-csv","owner":"vslinko","description":"Streaming API for reading and writing CSV for https://deno.land/","archived":false,"fork":false,"pushed_at":"2025-02-24T09:39:23.000Z","size":111,"stargazers_count":51,"open_issues_count":3,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T05:45:30.343Z","etag":null,"topics":["csv","deno"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vslinko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-05-14T22:52:47.000Z","updated_at":"2025-02-24T09:39:27.000Z","dependencies_parsed_at":"2024-01-16T07:22:24.122Z","dependency_job_id":"b641b76a-1944-402e-b252-119d6f738e47","html_url":"https://github.com/vslinko/deno-csv","commit_stats":{"total_commits":50,"total_committers":4,"mean_commits":12.5,"dds":0.06000000000000005,"last_synced_commit":"4fba77fdd52e702798531aeba516dfcb23abee14"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vslinko%2Fdeno-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vslinko%2Fdeno-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vslinko%2Fdeno-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vslinko%2Fdeno-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vslinko","download_url":"https://codeload.github.com/vslinko/deno-csv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248565003,"owners_count":21125413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","deno"],"created_at":"2024-07-31T17:01:48.054Z","updated_at":"2025-04-12T11:51:26.879Z","avatar_url":"https://github.com/vslinko.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# deno-csv\n\n\u003e Streaming API for reading and writing CSV for https://deno.land/.\n\n[![tag](https://img.shields.io/github/tag/vslinko/deno-csv.svg)](https://github.com/vslinko/deno-csv)\n[![Build Status](https://github.com/vslinko/deno-csv/workflows/ci/badge.svg?branch=master)](https://github.com/vslinko/deno-csv/actions)\n[![license](https://img.shields.io/github/license/vslinko/deno-csv.svg)](https://github.com/vslinko/deno-csv)\n[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/csv/mod.ts)\n\n## Usage\n\n### Reading\n\n#### Read CSV file\n\n```ts\nimport { readCSV } from \"jsr:@vslinko/csv\";\n\nconst f = await Deno.open(\"./example.csv\");\n\nfor await (const row of readCSV(f)) {\n  console.log(\"row:\");\n  for await (const cell of row) {\n    console.log(`  cell: ${cell}`);\n  }\n}\n\nf.close();\n```\n\n#### Read specific lines of CSV file\n\nLine numbering starts from zero. `fromLine` is inclusive, `toLine` is exclusive.\n\n```ts\nimport { readCSV } from \"jsr:@vslinko/csv\";\n\nconst f = await Deno.open(\"./example.csv\");\n\nfor await (const row of readCSV(f, { fromLine: 100, toLine: 200 })) {\n  console.log(\"row:\");\n  for await (const cell of row) {\n    console.log(`  cell: ${cell}`);\n  }\n}\n\nf.close();\n```\n\n#### Read CSV file with custom separators\n\n```ts\nimport { readCSV } from \"jsr:@vslinko/csv\";\n\nconst f = await Deno.open(\"./example.csv\");\n\nconst options = {\n  columnSeparator: \";\",\n  lineSeparator: \"\\r\\n\",\n  quote: \"$\",\n};\n\nfor await (const row of readCSV(f, options)) {\n  console.log(\"row:\");\n  for await (const cell of row) {\n    console.log(`  cell: ${cell}`);\n  }\n}\n\nf.close();\n```\n\n#### Read objects from CSV file with header row\n\n```ts\nimport { readCSVObjects } from \"jsr:@vslinko/csv\";\n\nconst f = await Deno.open(\"./example.csv\");\n\nfor await (const obj of readCSVObjects(f)) {\n  console.log(obj);\n}\n\nf.close();\n```\n\n#### Read CSV file manually\n\n```ts\nimport { readCSVObjects } from \"jsr:@vslinko/csv\";\n\nconst f = await Deno.open(\"./example.csv\");\n\nlet row: string[] = [];\nconst reader = new CSVReader(f, {\n  columnSeparator: \"\\t\",\n  lineSeparator: \"\\r\\n\",\n  onCell(cell: string) {\n    row.push(cell);\n  },\n  onRowEnd() {\n    console.log(row);\n    row = [];\n  },\n  onEnd() {\n    console.log(\"end\");\n    f.close();\n  },\n  onError(err) {\n    console.error(err);\n  },\n});\nreader.read();\n```\n\n### Writing\n\n#### Write CSV file\n\n```ts\nimport { writeCSV } from \"jsr:@vslinko/csv\";\n\nconst f = await Deno.open(\"./example.csv\", {\n  write: true,\n  create: true,\n  truncate: true,\n});\nconst rows = [\n  [\"a\", \"b\", \"c\"],\n  [\"1\", \"2\", \"3\"],\n];\n\nawait writeCSV(f, rows);\n\nf.close();\n```\n\n#### Write objects asynchronously to CSV file\n\n```ts\nimport { writeCSVObjects } from \"jsr:@vslinko/csv\";\n\nconst f = await Deno.open(\"./example.csv\", {\n  write: true,\n  create: true,\n  truncate: true,\n});\nconst header = [\"a\", \"b\", \"c\"];\nconst asyncObjectsGenerator = async function* () {\n  yield { a: \"1\", b: \"2\", c: \"3\" };\n  yield { a: \"4\", b: \"5\", c: \"6\" };\n};\n\nawait writeCSVObjects(f, asyncObjectsGenerator(), { header });\n\nf.close();\n```\n\n#### Write CSV file manually\n\n```ts\nimport { CSVWriter } from \"jsr:@vslinko/csv\";\n\nconst f = await Deno.open(\"./example.csv\", {\n  write: true,\n  create: true,\n  truncate: true,\n});\n\nconst writer = new CSVWriter(f, {\n  columnSeparator: \"\\t\",\n  lineSeparator: \"\\r\\n\",\n});\n\nawait writer.writeCell(\"a\");\nawait writer.writeCell(\"b\");\nawait writer.writeCell(\"c\");\nawait writer.nextLine();\nawait writer.writeCell(\"1\");\nawait writer.writeCell(\"2\");\nawait writer.writeCell(\"3\");\n\nf.close();\n```\n\n## Benchmarks\n\n```\ntest-node-csv-parse\nRead 500001 lines for 8.937 seconds\ntest-deno-csv-CSVReader\nRead 500001 lines for 8.986 seconds\ntest-deno-csv-readCSVRows\nRead 500001 lines for 9.425 seconds\ntest-deno-csv-readCSVStream\nRead 500001 lines for 13.657 seconds\ntest-deno-csv-readCSV\nRead 500001 lines for 15.814 seconds\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvslinko%2Fdeno-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvslinko%2Fdeno-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvslinko%2Fdeno-csv/lists"}