-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8e1ff9
commit f525810
Showing
10 changed files
with
67 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Question,Answer | ||
a dog,en hund | ||
the dog,hunden | ||
a cat,en katt | ||
the cat,katten | ||
a house,ett hus | ||
the house,huset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { extname } from "@std/path"; | ||
import { parse as parseYaml } from "@std/yaml"; | ||
import { Card, CardYaml } from "./card.ts"; | ||
import { parse as parseCsv } from "@std/csv"; | ||
|
||
async function loadDeck(filename: string): Promise<Card[]> { | ||
const ext = extname(filename); | ||
|
||
switch (ext) { | ||
case ".yaml": | ||
return await loadYamlDeck(filename); | ||
case ".csv": | ||
return await loadCsvDeck(filename); | ||
default: | ||
throw `unsupported extension: ${ext}`; | ||
} | ||
} | ||
|
||
async function loadYamlDeck(filename: string): Promise<Card[]> { | ||
const s = await Deno.readTextFile(filename); | ||
|
||
const { cards } = parseYaml(s) as { cards: CardYaml[] }; | ||
|
||
return cards.map(({ f, b }) => ({ front: f, back: b })); | ||
} | ||
|
||
type CsvCard = { | ||
Question: string; | ||
Answer: string; | ||
}; | ||
|
||
async function loadCsvDeck(filename: string): Promise<Card[]> { | ||
const csvContent = await Deno.readTextFile(filename); | ||
|
||
const parsedCsv = parseCsv( | ||
csvContent, | ||
{ | ||
header: true, | ||
skipFirstRow: true, | ||
}, | ||
) as CsvCard[]; | ||
|
||
return parsedCsv.map((row) => ({ | ||
front: row.Question, | ||
back: row.Answer, | ||
})); | ||
} | ||
|
||
export { loadDeck }; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.