-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanki-progressive.js
36 lines (33 loc) · 1.36 KB
/
anki-progressive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Generates `data/anki-progressive.tsv`, a list of kanji ordered first by
* the appearance of elements and second by the jouyou grade.
*
* This works by first generating the kanjiVE.json file, which is sorted
* purely based on the appearance of elements, with the exception of the
* order.txt kanji being injected artificially into the ordering
* (essentially forces the kanji for numbers 1-10 at the start).
*
* Once this list is generated, it then forcibly moves kanji up or down
* through the list based on the grade of the kanji in the jouyou list,
* resulting in grade 1 kanji appearing first and secondary school kanji
* appearing last.
*/
const fs = require("fs");
const colors = require("colors");
require("./ext");
const anki = require("./data/anki.json");
const ankiPath = "data/anki-progressive.tsv";
const lines = [];
// sort by grade
anki.sort(function(a,b){
return a.grade - b.grade;
});
console.log(`Create progressive jouyou flashcard file for anki.`.cyan)
for(let kanji of anki){
let named = [];
for(let element of kanji.elements) named.push(`${element.element}[${element.name}]`);
let line = [kanji.keyword, kanji.kanji, `grade${kanji.grade === 7 ? "S" : kanji.grade}`, kanji.frequency, named.join(" "), kanji.svg];
lines.push(line.join("\t"));
}
console.log(` ${">".cyan} Saving ${ankiPath.yellow}`);
fs.writeFileSync(ankiPath, lines.join("\n"));