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.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) => (!reading.notes || !reading.notes.some(
1227
+ (reading) => reading.notes === void 0 || !reading.notes.some(
1228
1228
  (note) => notSearchedForms.has(note)
1229
- )) && (entryObj.isCommon === void 0 || reading.commonness && reading.commonness.length > 0)
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) word.common = 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
- else if (translation.type === "expl")
1591
+ word.tags.push("word::literal_meaning");
1592
+ } else if (translation.type === "expl") {
1589
1593
  translationTypes.push("Explanation");
1590
- else if (translation.type === "tm")
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) word.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) delete word.kanji;
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) => (!reading.notes || !reading.notes.some(
1681
+ (reading) => reading.notes === void 0 || !reading.notes.some(
1669
1682
  (note) => notSearchedForms.has(note)
1670
- )) && (word.common === void 0 || reading.common === true)
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.map(
1675
- (kanjiForm) => kanjiForm.kanjiForm
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 = [];
@@ -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) throw new Error(`Invalid word: ${entry.noteID}`);
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
- entry.kanjiForms.map(
1988
- (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>" : ""}`
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
- entry.translations.map(
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>`,