From ac8c77d7c18bd4ebd989b18f3408a4225d90f347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 8 Apr 2026 08:49:44 +0200 Subject: [PATCH] docs: add file reading example to CSV parsing page Show how to read and parse a CSV file using Deno.readTextFile before the existing hardcoded string examples. Closes #2894 Co-Authored-By: Claude Opus 4.6 (1M context) --- examples/scripts/parsing_serializing_csv.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/scripts/parsing_serializing_csv.ts b/examples/scripts/parsing_serializing_csv.ts index c63713762..84650345a 100644 --- a/examples/scripts/parsing_serializing_csv.ts +++ b/examples/scripts/parsing_serializing_csv.ts @@ -2,7 +2,7 @@ * @title Parsing and serializing CSV * @difficulty beginner * @tags cli, deploy, web - * @run + * @run -R * @resource {/examples/import_export} Example: Importing & Exporting * @resource {https://datatracker.ietf.org/doc/html/rfc4180} Spec: CSV * @group Encoding @@ -11,8 +11,13 @@ */ import { parse, stringify } from "jsr:@std/csv"; -// To parse a CSV string, you can use the the standard library's CSV -// parse function. The value is returned as a JavaScript object. +// To parse a CSV file, read its contents and pass them to the parse function. +const fileContent = await Deno.readTextFile("data.csv"); +const fileData = parse(fileContent, { skipFirstRow: true }); +console.log(fileData); + +// You can also parse CSV strings directly. The value is returned as an +// array of objects when skipFirstRow is true. let text = ` url,views,likes https://deno.land,10,7