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.mjs
CHANGED
|
@@ -1224,9 +1224,9 @@ function convertJMdict(xmlString, examples) {
|
|
|
1224
1224
|
if (examples) {
|
|
1225
1225
|
const readings2 = new Set(
|
|
1226
1226
|
entryObj.readings.filter(
|
|
1227
|
-
(reading) =>
|
|
1227
|
+
(reading) => reading.notes === void 0 || !reading.notes.some(
|
|
1228
1228
|
(note) => notSearchedForms.has(note)
|
|
1229
|
-
)
|
|
1229
|
+
) || reading.commonness && reading.commonness.length > 0
|
|
1230
1230
|
).map((reading) => reading.reading)
|
|
1231
1231
|
);
|
|
1232
1232
|
const kanjiForms2 = entryObj.kanjiForms ? new Set(
|
|
@@ -1534,7 +1534,10 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1534
1534
|
...deckPath ? { deckPath } : {},
|
|
1535
1535
|
tags: []
|
|
1536
1536
|
};
|
|
1537
|
-
if (dictWord.isCommon === true)
|
|
1537
|
+
if (dictWord.isCommon === true) {
|
|
1538
|
+
word.common = true;
|
|
1539
|
+
word.tags.push("word::common");
|
|
1540
|
+
}
|
|
1538
1541
|
if (dictWord.kanjiForms)
|
|
1539
1542
|
word.kanjiForms = dictWord.kanjiForms.map(
|
|
1540
1543
|
(dictKanjiForm) => ({
|
|
@@ -1583,12 +1586,16 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1583
1586
|
(translation) => {
|
|
1584
1587
|
if (typeof translation === "string") return translation;
|
|
1585
1588
|
else {
|
|
1586
|
-
if (translation.type === "lit")
|
|
1589
|
+
if (translation.type === "lit") {
|
|
1587
1590
|
translationTypes.push("Literal meaning");
|
|
1588
|
-
|
|
1591
|
+
word.tags.push("word::literal_meaning");
|
|
1592
|
+
} else if (translation.type === "expl") {
|
|
1589
1593
|
translationTypes.push("Explanation");
|
|
1590
|
-
|
|
1594
|
+
word.tags.push("word::explanation");
|
|
1595
|
+
} else if (translation.type === "tm") {
|
|
1591
1596
|
translationTypes.push("Trademark");
|
|
1597
|
+
word.tags.push("word::trademark");
|
|
1598
|
+
}
|
|
1592
1599
|
return translation.translation;
|
|
1593
1600
|
}
|
|
1594
1601
|
}
|
|
@@ -1638,7 +1645,10 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1638
1645
|
notes
|
|
1639
1646
|
};
|
|
1640
1647
|
});
|
|
1641
|
-
if (dictWord.usuallyInKana === true)
|
|
1648
|
+
if (dictWord.usuallyInKana === true) {
|
|
1649
|
+
word.usuallyInKana = true;
|
|
1650
|
+
word.tags.push("word::usually_in_kana_for_all_senses");
|
|
1651
|
+
}
|
|
1642
1652
|
if (kanjiDic && word.kanjiForms) {
|
|
1643
1653
|
word.kanji = [];
|
|
1644
1654
|
for (const kanjiForm of word.kanjiForms)
|
|
@@ -1660,20 +1670,32 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1660
1670
|
});
|
|
1661
1671
|
}
|
|
1662
1672
|
}
|
|
1663
|
-
if (word.kanji.length === 0)
|
|
1673
|
+
if (word.kanji.length === 0) {
|
|
1674
|
+
delete word.kanji;
|
|
1675
|
+
word.tags.push("word::no_kanji");
|
|
1676
|
+
}
|
|
1664
1677
|
}
|
|
1665
1678
|
if (dictWord.hasPhrases === true && examples) {
|
|
1666
1679
|
const readings = new Set(
|
|
1667
1680
|
word.readings.filter(
|
|
1668
|
-
(reading) =>
|
|
1681
|
+
(reading) => reading.notes === void 0 || !reading.notes.some(
|
|
1669
1682
|
(note) => notSearchedForms.has(note)
|
|
1670
|
-
)
|
|
1683
|
+
) || reading.common === true
|
|
1671
1684
|
).map((reading) => reading.reading)
|
|
1672
1685
|
);
|
|
1686
|
+
const existValidKf = word.kanjiForms && word.kanjiForms.length > 0 ? word.kanjiForms.some(
|
|
1687
|
+
(kf) => kf.notes === void 0 || !kf.notes.some(
|
|
1688
|
+
(note) => notSearchedForms.has(note)
|
|
1689
|
+
) || kf.common === true
|
|
1690
|
+
) : void 0;
|
|
1673
1691
|
const kanjiForms = word.kanjiForms && word.kanjiForms.length > 0 ? new Set(
|
|
1674
|
-
word.kanjiForms.
|
|
1675
|
-
(
|
|
1676
|
-
|
|
1692
|
+
word.kanjiForms.filter((kanjiForm) => {
|
|
1693
|
+
if (existValidKf === true)
|
|
1694
|
+
return kanjiForm.notes === void 0 || !kanjiForm.notes.some(
|
|
1695
|
+
(note) => notSearchedForms.has(note)
|
|
1696
|
+
) || kanjiForm.common === true;
|
|
1697
|
+
else return true;
|
|
1698
|
+
}).map((kanjiForm) => kanjiForm.kanjiForm)
|
|
1677
1699
|
) : void 0;
|
|
1678
1700
|
const kanjiFormExamples = [];
|
|
1679
1701
|
const readingMatchingKanjiFormExamples = [];
|
|
@@ -1709,7 +1731,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1709
1731
|
for (let i = 0; i < word.translations.length; i++) {
|
|
1710
1732
|
outer: for (const example of wordExamples) {
|
|
1711
1733
|
if (seenPhrases.has(example.ex.phrase)) continue;
|
|
1712
|
-
for (let j = 0; j < example.ex.parts.length;
|
|
1734
|
+
for (let j = 0; j < example.ex.parts.length; j++) {
|
|
1713
1735
|
const part = example.ex.parts[j];
|
|
1714
1736
|
if (j === example.partIndex && part.glossNumber === i + 1) {
|
|
1715
1737
|
example.ex.glossNumber = {
|
|
@@ -1733,13 +1755,17 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1733
1755
|
(ex) => !seenPhrases.has(ex.ex.phrase)
|
|
1734
1756
|
).slice(0, 5 - glossSpecificExamples.length)
|
|
1735
1757
|
];
|
|
1736
|
-
if (wordExamples.length > 0)
|
|
1758
|
+
if (wordExamples.length > 0) {
|
|
1737
1759
|
word.phrases = (wordExamples.length > 5 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => ({
|
|
1738
1760
|
phrase: ex.ex.furigana ?? ex.ex.phrase,
|
|
1739
1761
|
translation: ex.ex.translation,
|
|
1740
1762
|
originalPhrase: ex.ex.phrase,
|
|
1741
1763
|
...ex.ex.glossNumber ? { glossNumber: ex.ex.glossNumber } : {}
|
|
1742
1764
|
}));
|
|
1765
|
+
word.tags.push("word::has_phrases");
|
|
1766
|
+
if (glossSpecificExamples.length > 0)
|
|
1767
|
+
word.tags.push("word::has_meaning-specific_phrases");
|
|
1768
|
+
}
|
|
1743
1769
|
}
|
|
1744
1770
|
return word;
|
|
1745
1771
|
} else throw new Error(`Word${id ? ` ${id}` : ""} not found`);
|
|
@@ -1981,26 +2007,50 @@ function generateAnkiNote(entry) {
|
|
|
1981
2007
|
if (!entry.noteID) throw new Error("Invalid note ID");
|
|
1982
2008
|
const fields = [];
|
|
1983
2009
|
if (isWord(entry)) {
|
|
1984
|
-
if (!entry.translations
|
|
2010
|
+
if (!entry.translations || entry.readings.length === 0)
|
|
2011
|
+
throw new Error(`Invalid word: ${entry.noteID}`);
|
|
2012
|
+
const firstReading = createEntry(
|
|
2013
|
+
`<span class="word word-reading">${entry.readings[0].reading}${entry.readings[0].audio !== void 0 ? `<br>[sound:${entry.readings[0].audio}]` : ""}</span>`,
|
|
2014
|
+
entry.readings[0].notes
|
|
2015
|
+
);
|
|
2016
|
+
const otherReadings = entry.readings.length > 1 ? `<details><summary>Show other readings</summary>${entry.readings.slice(1).map(
|
|
2017
|
+
(readingEntry) => createEntry(
|
|
2018
|
+
`<span class="word word-reading">${readingEntry.reading}${readingEntry.audio !== void 0 ? `<br>[sound:${readingEntry.audio}]` : ""}</span>`,
|
|
2019
|
+
readingEntry.notes
|
|
2020
|
+
)
|
|
2021
|
+
).join("")}</details>` : void 0;
|
|
2022
|
+
const readingsField = [firstReading, ...otherReadings ?? []].join(
|
|
2023
|
+
""
|
|
2024
|
+
);
|
|
2025
|
+
const firstKanjiForm = entry.kanjiForms ? createEntry(
|
|
2026
|
+
`<span class="word word-kanjiform"><ruby><rb>${entry.kanjiForms[0].kanjiForm}</rb><rt>${entry.readings[0].reading}</rt></ruby></span>`,
|
|
2027
|
+
entry.kanjiForms[0].notes
|
|
2028
|
+
) : void 0;
|
|
2029
|
+
const otherKanjiForms = entry.kanjiForms && entry.kanjiForms.length > 1 ? `<details><summary>Show other kanji forms</summary>${entry.kanjiForms.slice(1).map((kanjiFormEntry) => {
|
|
2030
|
+
const restrictedReading = entry.readings.find(
|
|
2031
|
+
(r) => r.notes && r.notes.includes(
|
|
2032
|
+
`Reading restricted to ${kanjiFormEntry.kanjiForm}`
|
|
2033
|
+
)
|
|
2034
|
+
);
|
|
2035
|
+
return `${createEntry(`<span class="word word-kanjiform">${restrictedReading ? "<ruby><rb>" : ""}${kanjiFormEntry.kanjiForm}${restrictedReading ? `</rb><rt>${restrictedReading.reading}</rt></ruby>` : ""}</span>`, kanjiFormEntry.notes)}`;
|
|
2036
|
+
}).join("")}</details>` : void 0;
|
|
2037
|
+
const kanjiFormsField = firstKanjiForm ? [firstKanjiForm, ...otherKanjiForms ?? []].join("") : void 0;
|
|
2038
|
+
const firstThreeTranslations = entry.translations.slice(0, 3).map(
|
|
2039
|
+
(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)}`
|
|
2040
|
+
).join("");
|
|
2041
|
+
const otherTranslations = entry.translations.length > 3 ? `<details><summary>Show other translations</summary>${entry.translations.map(
|
|
2042
|
+
(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"
|
|
2043
|
+
).filter((translation) => translation !== "null").join("")}</details>` : void 0;
|
|
2044
|
+
const translationsField = [
|
|
2045
|
+
firstThreeTranslations,
|
|
2046
|
+
...otherTranslations ?? []
|
|
2047
|
+
].join("");
|
|
1985
2048
|
fields.push(
|
|
1986
|
-
...entry.kanjiForms && !entry.usuallyInKana ? [
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
).join(""),
|
|
1990
|
-
entry.readings.map(
|
|
1991
|
-
(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>" : ""}`
|
|
1992
|
-
).join("")
|
|
1993
|
-
] : [
|
|
1994
|
-
entry.readings.map(
|
|
1995
|
-
(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>" : ""}`
|
|
1996
|
-
).join(""),
|
|
1997
|
-
entry.kanjiForms ? entry.kanjiForms.map(
|
|
1998
|
-
(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>" : ""}`
|
|
1999
|
-
).join("") : noKanjiForms
|
|
2049
|
+
...entry.kanjiForms && kanjiFormsField && !entry.usuallyInKana ? [kanjiFormsField, readingsField] : [
|
|
2050
|
+
readingsField,
|
|
2051
|
+
entry.kanjiForms && kanjiFormsField ? kanjiFormsField : noKanjiForms
|
|
2000
2052
|
],
|
|
2001
|
-
|
|
2002
|
-
(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>" : ""}`
|
|
2003
|
-
).join(""),
|
|
2053
|
+
translationsField,
|
|
2004
2054
|
entry.kanji ? entry.kanji.map(
|
|
2005
2055
|
(kanjiEntry) => createEntry(
|
|
2006
2056
|
`<span class="word word-kanji">${kanjiEntry.kanji}${kanjiEntry.meanings === void 0 ? " (no meanings)" : ""}</span>`,
|