henkan 0.9.2 → 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.
Files changed (55) hide show
  1. package/dist/index.cjs.js +82 -32
  2. package/dist/index.cjs.js.map +2 -2
  3. package/dist/index.mjs +82 -32
  4. package/dist/index.mjs.map +2 -2
  5. package/dist/types/utils.d.ts.map +1 -1
  6. package/docs/api/functions/capitalizeString.md +1 -1
  7. package/docs/api/functions/convertJMdict.md +1 -1
  8. package/docs/api/functions/convertKanjiDic.md +1 -1
  9. package/docs/api/functions/convertKradFile.md +1 -1
  10. package/docs/api/functions/convertRadkFile.md +1 -1
  11. package/docs/api/functions/convertTanakaCorpus.md +1 -1
  12. package/docs/api/functions/generateAnkiNote.md +1 -1
  13. package/docs/api/functions/generateAnkiNotesFile.md +1 -1
  14. package/docs/api/functions/getKanji.md +1 -1
  15. package/docs/api/functions/getKanjiExtended.md +1 -1
  16. package/docs/api/functions/getWord.md +1 -1
  17. package/docs/api/functions/isStringArray.md +1 -1
  18. package/docs/api/functions/isValidArray.md +1 -1
  19. package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
  20. package/docs/api/functions/shuffleArray.md +1 -1
  21. package/docs/api/functions/synthesizeSpeech.md +1 -1
  22. package/docs/api/interfaces/DictKanji.md +5 -5
  23. package/docs/api/interfaces/DictKanjiForm.md +4 -4
  24. package/docs/api/interfaces/DictKanjiMisc.md +5 -5
  25. package/docs/api/interfaces/DictKanjiReading.md +3 -3
  26. package/docs/api/interfaces/DictKanjiReadingMeaning.md +3 -3
  27. package/docs/api/interfaces/DictKanjiReadingMeaningGroup.md +3 -3
  28. package/docs/api/interfaces/DictKanjiWithRadicals.md +3 -3
  29. package/docs/api/interfaces/DictMeaning.md +11 -11
  30. package/docs/api/interfaces/DictRadical.md +4 -4
  31. package/docs/api/interfaces/DictReading.md +5 -5
  32. package/docs/api/interfaces/DictWord.md +8 -8
  33. package/docs/api/interfaces/ExamplePart.md +7 -7
  34. package/docs/api/interfaces/GlossSpecificNumber.md +3 -3
  35. package/docs/api/interfaces/Grammar.md +15 -15
  36. package/docs/api/interfaces/GrammarMeaning.md +3 -3
  37. package/docs/api/interfaces/Kana.md +11 -11
  38. package/docs/api/interfaces/Kanji.md +22 -22
  39. package/docs/api/interfaces/KanjiComponent.md +3 -3
  40. package/docs/api/interfaces/KanjiForm.md +4 -4
  41. package/docs/api/interfaces/NoteAndTag.md +3 -3
  42. package/docs/api/interfaces/Phrase.md +5 -5
  43. package/docs/api/interfaces/Radical.md +16 -16
  44. package/docs/api/interfaces/Reading.md +5 -5
  45. package/docs/api/interfaces/ResultEntry.md +7 -7
  46. package/docs/api/interfaces/TanakaExample.md +7 -7
  47. package/docs/api/interfaces/Translation.md +3 -3
  48. package/docs/api/interfaces/UsefulRegExps.md +8 -8
  49. package/docs/api/interfaces/Word.md +14 -14
  50. package/docs/api/type-aliases/Dict.md +1 -1
  51. package/docs/api/type-aliases/DictName.md +1 -1
  52. package/docs/api/type-aliases/EntryType.md +1 -1
  53. package/docs/api/type-aliases/JLPT.md +1 -1
  54. package/docs/api/type-aliases/Result.md +1 -1
  55. 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) => (!reading.notes || !reading.notes.some(
1277
+ (reading) => reading.notes === void 0 || !reading.notes.some(
1278
1278
  (note) => notSearchedForms.has(note)
1279
- )) && (entryObj.isCommon === void 0 || reading.commonness && reading.commonness.length > 0)
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) word.common = 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
- else if (translation.type === "expl")
1643
+ word.tags.push("word::literal_meaning");
1644
+ } else if (translation.type === "expl") {
1641
1645
  translationTypes.push("Explanation");
1642
- else if (translation.type === "tm")
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) word.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) delete word.kanji;
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) => (!reading.notes || !reading.notes.some(
1733
+ (reading) => reading.notes === void 0 || !reading.notes.some(
1721
1734
  (note) => notSearchedForms.has(note)
1722
- )) && (word.common === void 0 || reading.common === true)
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.map(
1727
- (kanjiForm) => kanjiForm.kanjiForm
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 = [];
@@ -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) throw new Error(`Invalid word: ${entry.noteID}`);
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
- entry.kanjiForms.map(
2043
- (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>" : ""}`
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
- entry.translations.map(
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>`,