Skip to content

Instantly share code, notes, and snippets.

@mioe
Created January 30, 2023 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mioe/79cfbc40b964a4ccab34e76ba7ffb812 to your computer and use it in GitHub Desktop.
Save mioe/79cfbc40b964a4ccab34e76ba7ffb812 to your computer and use it in GitHub Desktop.
simple parse csv via Deno 🦕
import { parse as parseCsv } from 'https://deno.land/std@0.82.0/encoding/csv.ts'
const data = await parseCsv(await Deno.readTextFile('data.csv'))
const query = await parseCsv(await Deno.readTextFile('query.csv'))
if (import.meta.main) {
const Q = query.flatMap((row) => row)
const INDEX = {
name: 1,
owner_id: 3,
}
const result = data.filter((row: any) => Q.includes(row[INDEX.owner_id]))
const formatted = result
.map((row: any) => [
row[INDEX.owner_id],
'https://' + row[INDEX.name] + '.example.com',
])
.map((row) => `${row[0]};${row[1]}`)
.join('\n')
await Deno.writeTextFile('./result.csv', formatted)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment