Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit ae18c19

Browse files
author
Irene Alvarado
committed
Change loadCSV to readCSV
1 parent e4097c9 commit ae18c19

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎csv.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parse, ParseOptions } from 'https://deno.land/std@0.92.0/encoding/csv.ts'
22

3-
export async function loadCSV(path: string, options?: ParseOptions): Promise<unknown> {
3+
export async function readCSV(path: string, options?: ParseOptions): Promise<unknown> {
44
const raw = await Deno.readTextFile(path)
55
const content = await parse(raw, options)
66
return content

‎examples/csv-example.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Column, DataItem, stringify } from "https://deno.land/std@0.92.0/encoding/csv.ts";
2-
import { loadCSV, writeCSV } from '../csv.ts'
2+
import { readCSV, writeCSV } from '../csv.ts'
33

44
// Path to a csv file
55
const csvPath = './examples/read-example.csv';
@@ -14,7 +14,7 @@ Parse a csv file and return a string[][]
1414
[ "Three", "-3", "$3000" ]
1515
]
1616
*/
17-
const originalCSV = await loadCSV(csvPath)
17+
const originalCSV = await readCSV(csvPath)
1818
console.log(originalCSV)
1919

2020
/*
@@ -26,7 +26,7 @@ Parse a CSV file and skip the first row. Return an object[]
2626
{ Name: "Three", Amount: "-3", Price: "$3000" }
2727
]
2828
*/
29-
const skipFirstRowCSV = await loadCSV(csvPath, {
29+
const skipFirstRowCSV = await readCSV(csvPath, {
3030
skipFirstRow: true
3131
// separator: ',' // can use an optional separator. default is comma
3232
// trimLeadingSpace: false, // whether to trim the leading space. default is false
@@ -43,7 +43,7 @@ Parse a CSV file, skip the first row, and rename the column headers. Return an o
4343
{ id: "Three", quantity: "-3", cost: "$3000" }
4444
]
4545
*/
46-
const renameColumnsCSV = await loadCSV(csvPath, {
46+
const renameColumnsCSV = await readCSV(csvPath, {
4747
skipFirstRow: true,
4848
columns: ['id', 'quantity', 'cost'],
4949
});
@@ -58,7 +58,7 @@ Parse a CSV file, skip the first row, and apply a custom function to the second
5858
{ id: "Three", quantity: "-0.3", cost: "$3000" }
5959
]
6060
*/
61-
const parseColumnCSV = await loadCSV(csvPath, {
61+
const parseColumnCSV = await readCSV(csvPath, {
6262
skipFirstRow: true,
6363
columns: [
6464
{

‎tests/csv-test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { assertArrayIncludes } from "https://deno.land/std@0.92.0/testing/asserts.ts"
2-
import { loadCSV, writeCSV } from '../csv.ts'
2+
import { readCSV, writeCSV } from '../csv.ts'
33

44
const csvReadPath = './examples/read-example.csv'
55
const csvWritePath = './examples/write-example.csv'
66

77
Deno.test("reads a csv file", async () => {
8-
const csv = await loadCSV(csvReadPath) as ArrayLike<unknown>
8+
const csv = await readCSV(csvReadPath) as ArrayLike<unknown>
99

1010
assertArrayIncludes(csv, [[ "One", "500", "$0.5" ]]);
1111
});
1212

1313
Deno.test("reads a csv file without header", async () => {
14-
const csv = await loadCSV(csvReadPath, {
14+
const csv = await readCSV(csvReadPath, {
1515
skipFirstRow: true
1616
}) as ArrayLike<unknown>
1717

@@ -21,7 +21,7 @@ Deno.test("reads a csv file without header", async () => {
2121
Deno.test("writes a csv file", async () => {
2222
const data = `name,age\nRick,70\nSmith,14`
2323
await writeCSV(csvWritePath, data)
24-
const csv = await loadCSV(csvWritePath) as ArrayLike<unknown>
24+
const csv = await readCSV(csvWritePath) as ArrayLike<unknown>
2525

2626
assertArrayIncludes(csv, [[ "Rick", "70" ]]);
2727
});

0 commit comments

Comments
 (0)