henkan 0.9.1 → 0.9.3
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 +83 -33
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.mjs +83 -33
- package/dist/index.mjs.map +2 -2
- package/dist/types/utils.d.ts.map +1 -1
- 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/shuffleArray.md +1 -1
- package/docs/api/functions/synthesizeSpeech.md +1 -1
- package/docs/api/interfaces/DictKanji.md +5 -5
- 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/GlossSpecificNumber.md +3 -3
- 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 +22 -22
- package/docs/api/interfaces/KanjiComponent.md +3 -3
- package/docs/api/interfaces/KanjiForm.md +4 -4
- package/docs/api/interfaces/NoteAndTag.md +3 -3
- package/docs/api/interfaces/Phrase.md +5 -5
- package/docs/api/interfaces/Radical.md +16 -16
- package/docs/api/interfaces/Reading.md +5 -5
- 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 +8 -8
- 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 +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1274,9 +1274,9 @@ function convertJMdict(xmlString, examples) {
|
|
|
1274
1274
|
if (examples) {
|
|
1275
1275
|
const readings2 = new Set(
|
|
1276
1276
|
entryObj.readings.filter(
|
|
1277
|
-
(reading) =>
|
|
1277
|
+
(reading) => reading.notes === void 0 || !reading.notes.some(
|
|
1278
1278
|
(note) => notSearchedForms.has(note)
|
|
1279
|
-
)
|
|
1279
|
+
) || reading.commonness && reading.commonness.length > 0
|
|
1280
1280
|
).map((reading) => reading.reading)
|
|
1281
1281
|
);
|
|
1282
1282
|
const kanjiForms2 = entryObj.kanjiForms ? new Set(
|
|
@@ -1584,7 +1584,10 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1584
1584
|
...deckPath ? { deckPath } : {},
|
|
1585
1585
|
tags: []
|
|
1586
1586
|
};
|
|
1587
|
-
if (dictWord.isCommon === true)
|
|
1587
|
+
if (dictWord.isCommon === true) {
|
|
1588
|
+
word.common = true;
|
|
1589
|
+
word.tags.push("word::common");
|
|
1590
|
+
}
|
|
1588
1591
|
if (dictWord.kanjiForms)
|
|
1589
1592
|
word.kanjiForms = dictWord.kanjiForms.map(
|
|
1590
1593
|
(dictKanjiForm) => ({
|
|
@@ -1635,12 +1638,16 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1635
1638
|
(translation) => {
|
|
1636
1639
|
if (typeof translation === "string") return translation;
|
|
1637
1640
|
else {
|
|
1638
|
-
if (translation.type === "lit")
|
|
1641
|
+
if (translation.type === "lit") {
|
|
1639
1642
|
translationTypes.push("Literal meaning");
|
|
1640
|
-
|
|
1643
|
+
word.tags.push("word::literal_meaning");
|
|
1644
|
+
} else if (translation.type === "expl") {
|
|
1641
1645
|
translationTypes.push("Explanation");
|
|
1642
|
-
|
|
1646
|
+
word.tags.push("word::explanation");
|
|
1647
|
+
} else if (translation.type === "tm") {
|
|
1643
1648
|
translationTypes.push("Trademark");
|
|
1649
|
+
word.tags.push("word::trademark");
|
|
1650
|
+
}
|
|
1644
1651
|
return translation.translation;
|
|
1645
1652
|
}
|
|
1646
1653
|
}
|
|
@@ -1690,7 +1697,10 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1690
1697
|
notes
|
|
1691
1698
|
};
|
|
1692
1699
|
});
|
|
1693
|
-
if (dictWord.usuallyInKana === true)
|
|
1700
|
+
if (dictWord.usuallyInKana === true) {
|
|
1701
|
+
word.usuallyInKana = true;
|
|
1702
|
+
word.tags.push("word::usually_in_kana_for_all_senses");
|
|
1703
|
+
}
|
|
1694
1704
|
if (kanjiDic && word.kanjiForms) {
|
|
1695
1705
|
word.kanji = [];
|
|
1696
1706
|
for (const kanjiForm of word.kanjiForms)
|
|
@@ -1712,20 +1722,32 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1712
1722
|
});
|
|
1713
1723
|
}
|
|
1714
1724
|
}
|
|
1715
|
-
if (word.kanji.length === 0)
|
|
1725
|
+
if (word.kanji.length === 0) {
|
|
1726
|
+
delete word.kanji;
|
|
1727
|
+
word.tags.push("word::no_kanji");
|
|
1728
|
+
}
|
|
1716
1729
|
}
|
|
1717
1730
|
if (dictWord.hasPhrases === true && examples) {
|
|
1718
1731
|
const readings = new Set(
|
|
1719
1732
|
word.readings.filter(
|
|
1720
|
-
(reading) =>
|
|
1733
|
+
(reading) => reading.notes === void 0 || !reading.notes.some(
|
|
1721
1734
|
(note) => notSearchedForms.has(note)
|
|
1722
|
-
)
|
|
1735
|
+
) || reading.common === true
|
|
1723
1736
|
).map((reading) => reading.reading)
|
|
1724
1737
|
);
|
|
1738
|
+
const existValidKf = word.kanjiForms && word.kanjiForms.length > 0 ? word.kanjiForms.some(
|
|
1739
|
+
(kf) => kf.notes === void 0 || !kf.notes.some(
|
|
1740
|
+
(note) => notSearchedForms.has(note)
|
|
1741
|
+
) || kf.common === true
|
|
1742
|
+
) : void 0;
|
|
1725
1743
|
const kanjiForms = word.kanjiForms && word.kanjiForms.length > 0 ? new Set(
|
|
1726
|
-
word.kanjiForms.
|
|
1727
|
-
(
|
|
1728
|
-
|
|
1744
|
+
word.kanjiForms.filter((kanjiForm) => {
|
|
1745
|
+
if (existValidKf === true)
|
|
1746
|
+
return kanjiForm.notes === void 0 || !kanjiForm.notes.some(
|
|
1747
|
+
(note) => notSearchedForms.has(note)
|
|
1748
|
+
) || kanjiForm.common === true;
|
|
1749
|
+
else return true;
|
|
1750
|
+
}).map((kanjiForm) => kanjiForm.kanjiForm)
|
|
1729
1751
|
) : void 0;
|
|
1730
1752
|
const kanjiFormExamples = [];
|
|
1731
1753
|
const readingMatchingKanjiFormExamples = [];
|
|
@@ -1761,7 +1783,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1761
1783
|
for (let i = 0; i < word.translations.length; i++) {
|
|
1762
1784
|
outer: for (const example of wordExamples) {
|
|
1763
1785
|
if (seenPhrases.has(example.ex.phrase)) continue;
|
|
1764
|
-
for (let j = 0; j < example.ex.parts.length;
|
|
1786
|
+
for (let j = 0; j < example.ex.parts.length; j++) {
|
|
1765
1787
|
const part = example.ex.parts[j];
|
|
1766
1788
|
if (j === example.partIndex && part.glossNumber === i + 1) {
|
|
1767
1789
|
example.ex.glossNumber = {
|
|
@@ -1785,7 +1807,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1785
1807
|
(ex) => !seenPhrases.has(ex.ex.phrase)
|
|
1786
1808
|
).slice(0, 5 - glossSpecificExamples.length)
|
|
1787
1809
|
];
|
|
1788
|
-
if (wordExamples.length > 0)
|
|
1810
|
+
if (wordExamples.length > 0) {
|
|
1789
1811
|
word.phrases = (wordExamples.length > 5 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => {
|
|
1790
1812
|
var _a;
|
|
1791
1813
|
return {
|
|
@@ -1795,6 +1817,10 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1795
1817
|
...ex.ex.glossNumber ? { glossNumber: ex.ex.glossNumber } : {}
|
|
1796
1818
|
};
|
|
1797
1819
|
});
|
|
1820
|
+
word.tags.push("word::has_phrases");
|
|
1821
|
+
if (glossSpecificExamples.length > 0)
|
|
1822
|
+
word.tags.push("word::has_meaning-specific_phrases");
|
|
1823
|
+
}
|
|
1798
1824
|
}
|
|
1799
1825
|
return word;
|
|
1800
1826
|
} else throw new Error(`Word${id ? ` ${id}` : ""} not found`);
|
|
@@ -2036,26 +2062,50 @@ function generateAnkiNote(entry) {
|
|
|
2036
2062
|
if (!entry.noteID) throw new Error("Invalid note ID");
|
|
2037
2063
|
const fields = [];
|
|
2038
2064
|
if (isWord(entry)) {
|
|
2039
|
-
if (!entry.translations
|
|
2065
|
+
if (!entry.translations || entry.readings.length === 0)
|
|
2066
|
+
throw new Error(`Invalid word: ${entry.noteID}`);
|
|
2067
|
+
const firstReading = createEntry(
|
|
2068
|
+
`<span class="word word-reading">${entry.readings[0].reading}${entry.readings[0].audio !== void 0 ? `<br>[sound:${entry.readings[0].audio}]` : ""}</span>`,
|
|
2069
|
+
entry.readings[0].notes
|
|
2070
|
+
);
|
|
2071
|
+
const otherReadings = entry.readings.length > 1 ? `<details><summary>Show other readings</summary>${entry.readings.slice(1).map(
|
|
2072
|
+
(readingEntry) => createEntry(
|
|
2073
|
+
`<span class="word word-reading">${readingEntry.reading}${readingEntry.audio !== void 0 ? `<br>[sound:${readingEntry.audio}]` : ""}</span>`,
|
|
2074
|
+
readingEntry.notes
|
|
2075
|
+
)
|
|
2076
|
+
).join("")}</details>` : void 0;
|
|
2077
|
+
const readingsField = [firstReading, ...otherReadings != null ? otherReadings : []].join(
|
|
2078
|
+
""
|
|
2079
|
+
);
|
|
2080
|
+
const firstKanjiForm = entry.kanjiForms ? createEntry(
|
|
2081
|
+
`<span class="word word-kanjiform"><ruby><rb>${entry.kanjiForms[0].kanjiForm}</rb><rt>${entry.readings[0].reading}</rt></ruby></span>`,
|
|
2082
|
+
entry.kanjiForms[0].notes
|
|
2083
|
+
) : void 0;
|
|
2084
|
+
const otherKanjiForms = entry.kanjiForms && entry.kanjiForms.length > 1 ? `<details><summary>Show other kanji forms</summary>${entry.kanjiForms.slice(1).map((kanjiFormEntry) => {
|
|
2085
|
+
const restrictedReading = entry.readings.find(
|
|
2086
|
+
(r) => r.notes && r.notes.includes(
|
|
2087
|
+
`Reading restricted to ${kanjiFormEntry.kanjiForm}`
|
|
2088
|
+
)
|
|
2089
|
+
);
|
|
2090
|
+
return `${createEntry(`<span class="word word-kanjiform">${restrictedReading ? "<ruby><rb>" : ""}${kanjiFormEntry.kanjiForm}${restrictedReading ? `</rb><rt>${restrictedReading.reading}</rt></ruby>` : ""}</span>`, kanjiFormEntry.notes)}`;
|
|
2091
|
+
}).join("")}</details>` : void 0;
|
|
2092
|
+
const kanjiFormsField = firstKanjiForm ? [firstKanjiForm, ...otherKanjiForms != null ? otherKanjiForms : []].join("") : void 0;
|
|
2093
|
+
const firstThreeTranslations = entry.translations.slice(0, 3).map(
|
|
2094
|
+
(translationEntry, index) => `${createEntry(`<span class="word word-translation">${translationEntry.translation}</span>`, translationEntry.notes, void 0, entry.phrases && entry.phrases.some((phrase, index2) => index === index2 && phrase.glossNumber && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1) ? true : void 0)}`
|
|
2095
|
+
).join("");
|
|
2096
|
+
const otherTranslations = entry.translations.length > 3 ? `<details><summary>Show other translations</summary>${entry.translations.map(
|
|
2097
|
+
(translationEntry, index) => index > 2 ? `${createEntry(`<span class="word word-translation">${translationEntry.translation}</span>`, translationEntry.notes, void 0, entry.phrases && entry.phrases.some((phrase, index2) => index === index2 && phrase.glossNumber && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1) ? true : void 0)}` : "null"
|
|
2098
|
+
).filter((translation) => translation !== "null").join("")}</details>` : void 0;
|
|
2099
|
+
const translationsField = [
|
|
2100
|
+
firstThreeTranslations,
|
|
2101
|
+
...otherTranslations != null ? otherTranslations : []
|
|
2102
|
+
].join("");
|
|
2040
2103
|
fields.push(
|
|
2041
|
-
...entry.kanjiForms && !entry.usuallyInKana ? [
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
).join(""),
|
|
2045
|
-
entry.readings.map(
|
|
2046
|
-
(readingEntry, index) => `${index > 0 ? "<details><summary>Show reading</summary>" : ""}${createEntry(`<span class="word word-reading">${readingEntry.reading}${readingEntry.audio !== void 0 ? `<br>[sound:${readingEntry.audio}]` : ""}</span>`, readingEntry.notes)}${index > 0 ? "</details>" : ""}`
|
|
2047
|
-
).join("")
|
|
2048
|
-
] : [
|
|
2049
|
-
entry.readings.map(
|
|
2050
|
-
(readingEntry, index) => `${index > 0 ? "<details><summary>Show reading</summary>" : ""}${createEntry(`<span class="word word-reading">${readingEntry.reading}${readingEntry.audio !== void 0 ? `<br>[sound:${readingEntry.audio}]` : ""}</span>`, readingEntry.notes)}${index > 0 ? "</details>" : ""}`
|
|
2051
|
-
).join(""),
|
|
2052
|
-
entry.kanjiForms ? entry.kanjiForms.map(
|
|
2053
|
-
(kanjiFormEntry, index) => `${index > 0 ? "<details><summary>Show kanji form</summary>" : ""}${createEntry(`<span class="word word-kanjiform">${index === 0 ? "<ruby><rb>" : ""}${kanjiFormEntry.kanjiForm}${index === 0 ? `</rb><rt>${entry.readings[0].reading}</rt></ruby>` : ""}</span>`, kanjiFormEntry.notes)}${index > 0 ? "</details>" : ""}`
|
|
2054
|
-
).join("") : noKanjiForms
|
|
2104
|
+
...entry.kanjiForms && kanjiFormsField && !entry.usuallyInKana ? [kanjiFormsField, readingsField] : [
|
|
2105
|
+
readingsField,
|
|
2106
|
+
entry.kanjiForms && kanjiFormsField ? kanjiFormsField : noKanjiForms
|
|
2055
2107
|
],
|
|
2056
|
-
|
|
2057
|
-
(translationEntry, index) => `${index > 2 ? "<details><summary>Show translation</summary>" : ""}${createEntry(`<span class="word word-translation">${translationEntry.translation}</span>`, translationEntry.notes, void 0, entry.phrases && entry.phrases.some((phrase, index2) => index === index2 && phrase.glossNumber && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1) ? true : void 0)}${index > 2 ? "</details>" : ""}`
|
|
2058
|
-
).join(""),
|
|
2108
|
+
translationsField,
|
|
2059
2109
|
entry.kanji ? entry.kanji.map(
|
|
2060
2110
|
(kanjiEntry) => createEntry(
|
|
2061
2111
|
`<span class="word word-kanji">${kanjiEntry.kanji}${kanjiEntry.meanings === void 0 ? " (no meanings)" : ""}</span>`,
|