henkan 0.9.0 → 0.9.2
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 +39 -41
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.mjs +39 -41
- 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 +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1670,7 +1670,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1670
1670
|
)) && (word.common === void 0 || reading.common === true)
|
|
1671
1671
|
).map((reading) => reading.reading)
|
|
1672
1672
|
);
|
|
1673
|
-
const kanjiForms = word.kanjiForms ? new Set(
|
|
1673
|
+
const kanjiForms = word.kanjiForms && word.kanjiForms.length > 0 ? new Set(
|
|
1674
1674
|
word.kanjiForms.map(
|
|
1675
1675
|
(kanjiForm) => kanjiForm.kanjiForm
|
|
1676
1676
|
)
|
|
@@ -1678,56 +1678,49 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1678
1678
|
const kanjiFormExamples = [];
|
|
1679
1679
|
const readingMatchingKanjiFormExamples = [];
|
|
1680
1680
|
const readingExamples = [];
|
|
1681
|
-
const partParts = /* @__PURE__ */ new Set();
|
|
1682
1681
|
for (const example of examples)
|
|
1683
|
-
for (
|
|
1684
|
-
const
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1682
|
+
for (let i = 0; i < example.parts.length; i++) {
|
|
1683
|
+
const part = example.parts[i];
|
|
1684
|
+
const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
|
|
1685
|
+
const readingAsInflectedFormMatch = part.inflectedForm !== void 0 && readings.has(part.inflectedForm);
|
|
1686
|
+
const referenceIDMatch = part.referenceID !== void 0 && word.id !== void 0 && part.referenceID === word.id;
|
|
1687
|
+
if (kanjiForms && kanjiForms.has(part.baseForm) || referenceIDMatch) {
|
|
1688
|
+
if (readingAsReadingMatch || readingAsInflectedFormMatch)
|
|
1689
|
+
readingMatchingKanjiFormExamples.push({
|
|
1690
|
+
ex: example,
|
|
1691
|
+
partIndex: i
|
|
1692
|
+
});
|
|
1693
|
+
else kanjiFormExamples.push({ ex: example, partIndex: i });
|
|
1693
1694
|
break;
|
|
1694
1695
|
}
|
|
1695
1696
|
const readingAsBaseFormMatch = readings.has(part.baseForm);
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
readingExamples.push(example);
|
|
1699
|
-
if (readingAsBaseFormMatch) partParts.add(part.baseForm);
|
|
1700
|
-
if (referenceIDMatch) partParts.add(part.referenceID);
|
|
1697
|
+
if ((readingAsBaseFormMatch || referenceIDMatch) && kanjiForms === void 0) {
|
|
1698
|
+
readingExamples.push({ ex: example, partIndex: i });
|
|
1701
1699
|
break;
|
|
1702
1700
|
}
|
|
1703
1701
|
}
|
|
1704
|
-
const exampleSize = readingMatchingKanjiFormExamples.length + kanjiFormExamples.length + readingExamples.length;
|
|
1705
|
-
const includeReadingThreshold = Math.max(
|
|
1706
|
-
10,
|
|
1707
|
-
Math.round(exampleSize * 0.5)
|
|
1708
|
-
);
|
|
1709
1702
|
const includeKanjiFormExamples = word.kanjiForms !== void 0;
|
|
1710
|
-
const includeReadingExamples = readingExamples.length >= includeReadingThreshold && readingExamples.length >= readingMatchingKanjiFormExamples.length && readingExamples.length >= kanjiFormExamples.length || readingExamples.length >= includeReadingThreshold && word.usuallyInKana === true || word.kanjiForms === void 0;
|
|
1711
1703
|
let wordExamples = [
|
|
1712
|
-
...readingMatchingKanjiFormExamples,
|
|
1713
|
-
|
|
1714
|
-
...includeReadingExamples ? readingExamples : []
|
|
1704
|
+
...includeKanjiFormExamples ? [...readingMatchingKanjiFormExamples, ...kanjiFormExamples] : [],
|
|
1705
|
+
...!includeKanjiFormExamples ? readingExamples : []
|
|
1715
1706
|
];
|
|
1716
1707
|
const glossSpecificExamples = [];
|
|
1717
1708
|
const seenPhrases = /* @__PURE__ */ new Set();
|
|
1718
1709
|
for (let i = 0; i < word.translations.length; i++) {
|
|
1719
1710
|
outer: for (const example of wordExamples) {
|
|
1720
|
-
if (seenPhrases.has(example.phrase)) continue;
|
|
1721
|
-
for (
|
|
1722
|
-
|
|
1723
|
-
|
|
1711
|
+
if (seenPhrases.has(example.ex.phrase)) continue;
|
|
1712
|
+
for (let j = 0; j < example.ex.parts.length; j++) {
|
|
1713
|
+
const part = example.ex.parts[j];
|
|
1714
|
+
if (j === example.partIndex && part.glossNumber === i + 1) {
|
|
1715
|
+
example.ex.glossNumber = {
|
|
1724
1716
|
wordId: word.id,
|
|
1725
1717
|
glossNumber: i + 1
|
|
1726
1718
|
};
|
|
1727
1719
|
glossSpecificExamples.push(example);
|
|
1728
|
-
seenPhrases.add(example.phrase);
|
|
1720
|
+
seenPhrases.add(example.ex.phrase);
|
|
1729
1721
|
break outer;
|
|
1730
1722
|
}
|
|
1723
|
+
}
|
|
1731
1724
|
}
|
|
1732
1725
|
if (glossSpecificExamples.length === 5) break;
|
|
1733
1726
|
}
|
|
@@ -1736,14 +1729,16 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1736
1729
|
else if (glossSpecificExamples.length > 0)
|
|
1737
1730
|
wordExamples = [
|
|
1738
1731
|
...glossSpecificExamples,
|
|
1739
|
-
...wordExamples.filter(
|
|
1732
|
+
...wordExamples.filter(
|
|
1733
|
+
(ex) => !seenPhrases.has(ex.ex.phrase)
|
|
1734
|
+
).slice(0, 5 - glossSpecificExamples.length)
|
|
1740
1735
|
];
|
|
1741
1736
|
if (wordExamples.length > 0)
|
|
1742
1737
|
word.phrases = (wordExamples.length > 5 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => ({
|
|
1743
|
-
phrase: ex.furigana ?? ex.phrase,
|
|
1744
|
-
translation: ex.translation,
|
|
1745
|
-
originalPhrase: ex.phrase,
|
|
1746
|
-
...ex.glossNumber ? { glossNumber: ex.glossNumber } : {}
|
|
1738
|
+
phrase: ex.ex.furigana ?? ex.ex.phrase,
|
|
1739
|
+
translation: ex.ex.translation,
|
|
1740
|
+
originalPhrase: ex.ex.phrase,
|
|
1741
|
+
...ex.ex.glossNumber ? { glossNumber: ex.ex.glossNumber } : {}
|
|
1747
1742
|
}));
|
|
1748
1743
|
}
|
|
1749
1744
|
return word;
|
|
@@ -1980,7 +1975,7 @@ function isGrammar(entry) {
|
|
|
1980
1975
|
return entry.point !== void 0 && entry.meaning !== void 0;
|
|
1981
1976
|
}
|
|
1982
1977
|
var createNotes = (notes, phrase) => `${phrase === true ? "<details><summary>Show translation</summary>" : ""}<ul class="note-list">${notes.map((note) => `<li class="note">${note}</li>`).join("")}</ul>${phrase === true ? "</details>" : ""}`;
|
|
1983
|
-
var createEntry = (entry, notes, phrase) => `<div class="entry">${entry}${notes && notes.length > 0 ? createNotes(notes, phrase) : ""}</div>`;
|
|
1978
|
+
var createEntry = (entry, notes, phrase, glossSpecific) => `<div class="entry${glossSpecific ? " gloss-specific" : ""}">${entry}${notes && notes.length > 0 ? createNotes(notes, phrase) : ""}</div>`;
|
|
1984
1979
|
var noKanjiForms = '<span class="word word-kanjiform">(no kanji forms)</span>';
|
|
1985
1980
|
function generateAnkiNote(entry) {
|
|
1986
1981
|
if (!entry.noteID) throw new Error("Invalid note ID");
|
|
@@ -2004,7 +1999,7 @@ function generateAnkiNote(entry) {
|
|
|
2004
1999
|
).join("") : noKanjiForms
|
|
2005
2000
|
],
|
|
2006
2001
|
entry.translations.map(
|
|
2007
|
-
(translationEntry, index) => `<span class="word word-
|
|
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>" : ""}`
|
|
2008
2003
|
).join(""),
|
|
2009
2004
|
entry.kanji ? entry.kanji.map(
|
|
2010
2005
|
(kanjiEntry) => createEntry(
|
|
@@ -2013,11 +2008,14 @@ function generateAnkiNote(entry) {
|
|
|
2013
2008
|
)
|
|
2014
2009
|
).join("") : '<span class="word word-kanji">(no kanji)</span>',
|
|
2015
2010
|
entry.phrases ? entry.phrases.map(
|
|
2016
|
-
(phraseEntry, index) =>
|
|
2011
|
+
(phraseEntry, index) => createEntry(
|
|
2017
2012
|
`<span class="word word-phrase"><span class="word word-phrase-original">${phraseEntry.originalPhrase}</span><span class="word word-phrase-furigana">${phraseEntry.phrase}</span></span>`,
|
|
2018
2013
|
[phraseEntry.translation],
|
|
2019
|
-
true
|
|
2020
|
-
|
|
2014
|
+
true,
|
|
2015
|
+
entry.translations.some(
|
|
2016
|
+
(_translation, index2) => index === index2 && phraseEntry.glossNumber && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2017
|
+
) ? true : void 0
|
|
2018
|
+
)
|
|
2021
2019
|
).join("") : '<span class="word word-phrase">(no phrases) (Search on dictionaries!)</span>',
|
|
2022
2020
|
...entry.tags && entry.tags.length > 0 ? [
|
|
2023
2021
|
entry.tags.map(
|