Skip to content

Commit fe2893e

Browse files
author
Irene Alvarado
committed
Fix csvWrite helper function which did not write strings anymore
1 parent 5e142ac commit fe2893e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

csv.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export async function readCSV(path: string, options?: ParseOptions): Promise<Rec
1515
return content as Record<string, unknown>[]
1616
}
1717

18-
export async function writeCSV(path: string, data: Record<string, unknown>[]) {
18+
export async function writeCSV(path: string, data: Record<string, unknown>[] | string) {
19+
if (typeof data === 'string') {
20+
await Deno.writeTextFile(path, data);
21+
return
22+
}
23+
1924
const headers = Object.keys(data[0])
2025
// we have to stringify the data with a row header
2126
const dataString = await stringify(data as DataItem[], headers)

examples/xlsx/xlsx-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { xlsx, readXLSX, writeCSV } from 'https://deno.land/x/[email protected]/mod.ts'
1+
import { xlsx, readXLSX } from '../../xlsx.ts'
2+
import { writeCSV } from '../../csv.ts'
23

34
const inputFilename = './examples/xlsx/prices.xlsx'
45
const outputFilename = './examples/xlsx/prices.csv'

0 commit comments

Comments
 (0)