henkan 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +106 -71
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +104 -71
- package/dist/index.mjs.map +3 -3
- package/dist/types/types.d.ts +24 -3
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/README.md +1 -0
- package/docs/api/functions/capitalizeString.md +1 -1
- package/docs/api/functions/convertJMdict.md +1 -1
- package/docs/api/functions/convertKanjiDic.md +1 -1
- package/docs/api/functions/convertKradFile.md +1 -1
- package/docs/api/functions/convertRadkFile.md +1 -1
- package/docs/api/functions/convertTanakaCorpus.md +1 -1
- package/docs/api/functions/generateAnkiNote.md +1 -1
- package/docs/api/functions/generateAnkiNotesFile.md +1 -1
- package/docs/api/functions/getKanji.md +1 -1
- package/docs/api/functions/getKanjiExtended.md +1 -1
- package/docs/api/functions/getWord.md +1 -1
- package/docs/api/functions/isStringArray.md +1 -1
- package/docs/api/functions/isValidArray.md +1 -1
- package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
- package/docs/api/functions/makeSSML.md +1 -1
- package/docs/api/functions/shuffleArray.md +1 -1
- package/docs/api/functions/synthesizeSpeech.md +1 -1
- package/docs/api/interfaces/DictKanji.md +14 -4
- package/docs/api/interfaces/DictKanjiForm.md +4 -4
- package/docs/api/interfaces/DictKanjiMisc.md +5 -5
- package/docs/api/interfaces/DictKanjiReading.md +3 -3
- package/docs/api/interfaces/DictKanjiReadingMeaning.md +3 -3
- package/docs/api/interfaces/DictKanjiReadingMeaningGroup.md +3 -3
- package/docs/api/interfaces/DictKanjiWithRadicals.md +3 -3
- package/docs/api/interfaces/DictMeaning.md +11 -11
- package/docs/api/interfaces/DictRadical.md +4 -4
- package/docs/api/interfaces/DictReading.md +5 -5
- package/docs/api/interfaces/DictWord.md +8 -8
- package/docs/api/interfaces/ExamplePart.md +7 -7
- package/docs/api/interfaces/Grammar.md +15 -15
- package/docs/api/interfaces/GrammarMeaning.md +3 -3
- package/docs/api/interfaces/Kana.md +11 -11
- package/docs/api/interfaces/Kanji.md +31 -21
- package/docs/api/interfaces/KanjiComponent.md +3 -3
- package/docs/api/interfaces/KanjiForm.md +3 -3
- package/docs/api/interfaces/NoteAndTag.md +31 -0
- package/docs/api/interfaces/Phrase.md +4 -4
- package/docs/api/interfaces/Radical.md +16 -16
- package/docs/api/interfaces/Reading.md +4 -4
- package/docs/api/interfaces/ResultEntry.md +7 -7
- package/docs/api/interfaces/TanakaExample.md +7 -7
- package/docs/api/interfaces/Translation.md +3 -3
- package/docs/api/interfaces/UsefulRegExps.md +9 -9
- package/docs/api/interfaces/Word.md +14 -14
- package/docs/api/type-aliases/Dict.md +1 -1
- package/docs/api/type-aliases/DictName.md +1 -1
- package/docs/api/type-aliases/EntryType.md +1 -1
- package/docs/api/type-aliases/JLPT.md +1 -1
- package/docs/api/type-aliases/Result.md +1 -1
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -1214,6 +1214,13 @@ function convertJMdict(xmlString, examples) {
|
|
|
1214
1214
|
const dict = [];
|
|
1215
1215
|
import_xml2js.default.parseString(dictParsed, (err, result) => {
|
|
1216
1216
|
if (err) throw err;
|
|
1217
|
+
let tanakaBaseParts = void 0;
|
|
1218
|
+
if (examples)
|
|
1219
|
+
tanakaBaseParts = new Set(
|
|
1220
|
+
examples.map(
|
|
1221
|
+
(example) => example.parts.map((part) => part.baseForm)
|
|
1222
|
+
).flat()
|
|
1223
|
+
);
|
|
1217
1224
|
if (result.JMdict && typeof result.JMdict === "object" && isValidArray(result.JMdict.entry))
|
|
1218
1225
|
for (const entry of result.JMdict.entry) {
|
|
1219
1226
|
const entryObj = {
|
|
@@ -1309,21 +1316,19 @@ function convertJMdict(xmlString, examples) {
|
|
|
1309
1316
|
) : void 0;
|
|
1310
1317
|
let kanjiFormExamples = false;
|
|
1311
1318
|
let readingExamples = false;
|
|
1312
|
-
if (kanjiForms2) {
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}
|
|
1319
|
+
if (kanjiForms2 && kanjiForms2.size > 0 && tanakaBaseParts) {
|
|
1320
|
+
for (const kf of kanjiForms2)
|
|
1321
|
+
if (tanakaBaseParts.has(kf)) {
|
|
1322
|
+
kanjiFormExamples = true;
|
|
1323
|
+
break;
|
|
1324
|
+
}
|
|
1319
1325
|
}
|
|
1320
|
-
if (!kanjiFormExamples) {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
}
|
|
1326
|
+
if (!kanjiFormExamples && readings2.size > 0 && tanakaBaseParts) {
|
|
1327
|
+
for (const r of readings2)
|
|
1328
|
+
if (tanakaBaseParts.has(r)) {
|
|
1329
|
+
readingExamples = true;
|
|
1330
|
+
break;
|
|
1331
|
+
}
|
|
1327
1332
|
}
|
|
1328
1333
|
if (kanjiFormExamples || readingExamples)
|
|
1329
1334
|
entryObj.hasPhrases = true;
|
|
@@ -1392,8 +1397,11 @@ function convertKanjiDic(xmlString) {
|
|
|
1392
1397
|
}
|
|
1393
1398
|
if (isValidArray(group.meaning)) {
|
|
1394
1399
|
for (const meaning of group.meaning)
|
|
1395
|
-
if (typeof meaning === "string")
|
|
1400
|
+
if (typeof meaning === "string") {
|
|
1401
|
+
if (kanjiObj.isKokuji === void 0 && meaning === "(kokuji)")
|
|
1402
|
+
kanjiObj.isKokuji = true;
|
|
1396
1403
|
groupObj.meanings.push(meaning);
|
|
1404
|
+
}
|
|
1397
1405
|
}
|
|
1398
1406
|
if (groupObj.readings.length > 0 || groupObj.meanings.length > 0)
|
|
1399
1407
|
rmObj.groups.push(groupObj);
|
|
@@ -1575,11 +1583,12 @@ function lookupWordNote(key, notes, tags, required, fallback) {
|
|
|
1575
1583
|
);
|
|
1576
1584
|
if (!info) {
|
|
1577
1585
|
if (required) throw new Error(`Invalid note info for ${key}`);
|
|
1578
|
-
notes.push(fallback != null ? fallback : key);
|
|
1579
|
-
return;
|
|
1586
|
+
if (notes) notes.push(fallback != null ? fallback : key);
|
|
1587
|
+
return { note: fallback != null ? fallback : key };
|
|
1580
1588
|
}
|
|
1581
|
-
tags.push(info[0]);
|
|
1582
|
-
notes.push(info[1]);
|
|
1589
|
+
if (tags) tags.push(`word::${info[0]}`);
|
|
1590
|
+
if (notes) notes.push(info[1]);
|
|
1591
|
+
return { note: info[1], tag: `word::${info[0]}` };
|
|
1583
1592
|
}
|
|
1584
1593
|
var wordAddNoteArray = (arr, cb) => {
|
|
1585
1594
|
if (!arr) return;
|
|
@@ -1596,40 +1605,50 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1596
1605
|
translations: [],
|
|
1597
1606
|
noteID: `word_${dictWord.id}`,
|
|
1598
1607
|
...noteTypeName ? { noteTypeName } : {},
|
|
1599
|
-
...deckPath ? { deckPath } : {}
|
|
1608
|
+
...deckPath ? { deckPath } : {},
|
|
1609
|
+
tags: []
|
|
1600
1610
|
};
|
|
1611
|
+
if (dictWord.isCommon === true) word.common = true;
|
|
1601
1612
|
if (dictWord.kanjiForms)
|
|
1602
1613
|
word.kanjiForms = dictWord.kanjiForms.map(
|
|
1603
|
-
(dictKanjiForm) => {
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1614
|
+
(dictKanjiForm) => ({
|
|
1615
|
+
kanjiForm: dictKanjiForm.form,
|
|
1616
|
+
...dictKanjiForm.notes ? {
|
|
1617
|
+
notes: dictKanjiForm.notes.map((note) => {
|
|
1618
|
+
var _a;
|
|
1619
|
+
const noteAndTag = lookupWordNote(
|
|
1620
|
+
note,
|
|
1621
|
+
void 0,
|
|
1622
|
+
word.tags,
|
|
1623
|
+
false,
|
|
1624
|
+
note
|
|
1625
|
+
);
|
|
1626
|
+
return capitalizeString((_a = noteAndTag.note) != null ? _a : note);
|
|
1627
|
+
})
|
|
1628
|
+
} : {}
|
|
1629
|
+
})
|
|
1615
1630
|
);
|
|
1616
|
-
word.readings = dictWord.readings.map((dictReading) => {
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1631
|
+
word.readings = dictWord.readings.map((dictReading) => ({
|
|
1632
|
+
reading: dictReading.reading,
|
|
1633
|
+
...dictReading.kanjiFormRestrictions || dictReading.notes ? {
|
|
1634
|
+
notes: [
|
|
1635
|
+
...dictReading.kanjiFormRestrictions ? dictReading.kanjiFormRestrictions.map(
|
|
1636
|
+
(restriction) => `Reading restricted to ${restriction}`
|
|
1637
|
+
) : [],
|
|
1638
|
+
...dictReading.notes ? dictReading.notes.map((note) => {
|
|
1639
|
+
var _a;
|
|
1640
|
+
const noteAndTag = lookupWordNote(
|
|
1641
|
+
note,
|
|
1642
|
+
void 0,
|
|
1643
|
+
word.tags,
|
|
1644
|
+
false,
|
|
1645
|
+
note
|
|
1646
|
+
);
|
|
1647
|
+
return capitalizeString((_a = noteAndTag.note) != null ? _a : note);
|
|
1648
|
+
}) : []
|
|
1649
|
+
]
|
|
1650
|
+
} : {}
|
|
1651
|
+
}));
|
|
1633
1652
|
let usuallyInKanaMeanings = 0;
|
|
1634
1653
|
word.translations = dictWord.meanings.map((dictMeaning) => {
|
|
1635
1654
|
if (!dictMeaning.translations)
|
|
@@ -1650,7 +1669,6 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1650
1669
|
}
|
|
1651
1670
|
);
|
|
1652
1671
|
const notes = [];
|
|
1653
|
-
word.tags = [];
|
|
1654
1672
|
wordAddNoteArray(
|
|
1655
1673
|
dictMeaning.kanjiFormRestrictions,
|
|
1656
1674
|
(restriction) => notes.push(`Meaning restricted to ${restriction}`)
|
|
@@ -1721,7 +1739,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1721
1739
|
}
|
|
1722
1740
|
if (word.kanji.length === 0) delete word.kanji;
|
|
1723
1741
|
}
|
|
1724
|
-
if (examples) {
|
|
1742
|
+
if (examples && dictWord.hasPhrases === true) {
|
|
1725
1743
|
const readings = new Set(
|
|
1726
1744
|
word.readings.filter(
|
|
1727
1745
|
(reading) => !reading.notes || reading.notes && !reading.notes.some(
|
|
@@ -1793,6 +1811,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1793
1811
|
}
|
|
1794
1812
|
}
|
|
1795
1813
|
function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
1814
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1796
1815
|
try {
|
|
1797
1816
|
const dictKanji = dict.find(
|
|
1798
1817
|
(entry) => entry.kanji === kanjiChar
|
|
@@ -1907,26 +1926,28 @@ function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
|
1907
1926
|
let codePoint = kanji.kanji.codePointAt(0);
|
|
1908
1927
|
if (codePoint !== void 0) {
|
|
1909
1928
|
codePoint = codePoint.toString(16);
|
|
1929
|
+
const fileNames = [
|
|
1930
|
+
`0${codePoint}.svg`,
|
|
1931
|
+
`${codePoint}.svg`
|
|
1932
|
+
];
|
|
1910
1933
|
const svg = svgList.find(
|
|
1911
|
-
(svgFile) =>
|
|
1934
|
+
(svgFile) => fileNames.includes(svgFile.toLowerCase())
|
|
1912
1935
|
);
|
|
1913
1936
|
if (svg) kanji.svg = svg;
|
|
1914
1937
|
}
|
|
1915
1938
|
}
|
|
1916
1939
|
kanji.tags = [];
|
|
1917
|
-
if (
|
|
1918
|
-
kanji.
|
|
1919
|
-
kanji.
|
|
1920
|
-
(meaning) => meaning !== "(kokuji)"
|
|
1921
|
-
);
|
|
1940
|
+
if (dictKanji.isKokuji === true) {
|
|
1941
|
+
kanji.kokuji = true;
|
|
1942
|
+
kanji.tags.push("kanji::kokuji");
|
|
1922
1943
|
}
|
|
1923
1944
|
kanji.tags.push(
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
...kanji.
|
|
1945
|
+
`kanji::onyomi::${(_b = (_a = kanji.onyomi) == null ? void 0 : _a.length) != null ? _b : 0}`,
|
|
1946
|
+
`kanji::kunyomi::${(_d = (_c = kanji.kunyomi) == null ? void 0 : _c.length) != null ? _d : 0}`,
|
|
1947
|
+
`kanji::nanori::${(_f = (_e = kanji.nanori) == null ? void 0 : _e.length) != null ? _f : 0}`,
|
|
1948
|
+
`kanji::strokes::${(_g = kanji.strokes) != null ? _g : "unknown"}`,
|
|
1949
|
+
`kanji::words::${(_i = (_h = kanji.words) == null ? void 0 : _h.length) != null ? _i : 0}`,
|
|
1950
|
+
...kanji.svg ? ["kanji::has_svg"] : []
|
|
1930
1951
|
);
|
|
1931
1952
|
return kanji;
|
|
1932
1953
|
} else throw new Error(`Kanji ${kanjiChar} not found`);
|
|
@@ -1935,6 +1956,7 @@ function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
|
1935
1956
|
}
|
|
1936
1957
|
}
|
|
1937
1958
|
function getKanjiExtended(kanjiChar, info, dict, useJpdbWords, jmDict, svgList, noteTypeName, deckPath) {
|
|
1959
|
+
var _a, _b, _c, _d;
|
|
1938
1960
|
try {
|
|
1939
1961
|
const kanji = getKanji(
|
|
1940
1962
|
kanjiChar,
|
|
@@ -1950,12 +1972,25 @@ function getKanjiExtended(kanjiChar, info, dict, useJpdbWords, jmDict, svgList,
|
|
|
1950
1972
|
kanji.mnemonic = info.mnemonic;
|
|
1951
1973
|
if (useJpdbWords === true && info.words && info.words.length > 0)
|
|
1952
1974
|
kanji.words = info.words;
|
|
1953
|
-
if (kanji.
|
|
1954
|
-
kanji.tags.push(
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1975
|
+
if (kanji.tags) {
|
|
1976
|
+
kanji.tags.push(`kanji::components::${(_b = (_a = kanji.components) == null ? void 0 : _a.length) != null ? _b : 0}`);
|
|
1977
|
+
if (kanji.mnemonic && kanji.mnemonic.length > 0)
|
|
1978
|
+
kanji.tags.push("kanji::has_mnemonic");
|
|
1979
|
+
if (useJpdbWords === true && kanji.words) {
|
|
1980
|
+
if (!kanji.tags.some((tag, index) => {
|
|
1981
|
+
var _a2, _b2;
|
|
1982
|
+
if (tag.startsWith("kanji::words::")) {
|
|
1983
|
+
kanji.tags.splice(
|
|
1984
|
+
index,
|
|
1985
|
+
1,
|
|
1986
|
+
`kanji::words::${(_b2 = (_a2 = kanji.words) == null ? void 0 : _a2.length) != null ? _b2 : 0}`
|
|
1987
|
+
);
|
|
1988
|
+
return true;
|
|
1989
|
+
} else return false;
|
|
1990
|
+
}))
|
|
1991
|
+
kanji.tags.push(`kanji::words::${(_d = (_c = kanji.words) == null ? void 0 : _c.length) != null ? _d : 0}`);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1959
1994
|
if (kanji.fromJpdb === true && (kanji.mnemonic || kanji.components && kanji.components.length > 0 || kanji.words))
|
|
1960
1995
|
kanji.source = `https://jpdb.io/kanji/${kanji.kanji}#a`;
|
|
1961
1996
|
return kanji;
|
|
@@ -2160,12 +2195,12 @@ function generateAnkiNote(entry) {
|
|
|
2160
2195
|
(onyomiEntry) => createEntry(
|
|
2161
2196
|
`<span class="kanji kanji-onyomi">${onyomiEntry}</span>`
|
|
2162
2197
|
)
|
|
2163
|
-
).join("") :
|
|
2198
|
+
).join("") : `<span class="kanji kanji-onyomi">(no onyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span`,
|
|
2164
2199
|
entry.kunyomi ? entry.kunyomi.map(
|
|
2165
2200
|
(kunyomiEntry) => createEntry(
|
|
2166
2201
|
`<span class="kanji kanji-kunyomi">${kunyomiEntry}</span>`
|
|
2167
2202
|
)
|
|
2168
|
-
).join("") :
|
|
2203
|
+
).join("") : `<span class="kanji kanji-kunyomi">(no kunyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
|
|
2169
2204
|
entry.nanori ? entry.nanori.map(
|
|
2170
2205
|
(nanoriEntry) => createEntry(
|
|
2171
2206
|
`<span class="kanji kanji-nanori">${nanoriEntry}</span>`
|