henkan 0.0.3 → 0.1.1

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 (56) hide show
  1. package/dist/index.cjs.js +24 -17
  2. package/dist/index.cjs.js.map +2 -2
  3. package/dist/index.mjs +21 -14
  4. package/dist/index.mjs.map +2 -2
  5. package/dist/types/types.d.ts +10 -0
  6. package/dist/types/types.d.ts.map +1 -1
  7. package/dist/types/utils.d.ts.map +1 -1
  8. package/docs/api/functions/capitalizeString.md +1 -1
  9. package/docs/api/functions/convertJMdict.md +1 -1
  10. package/docs/api/functions/convertKanjiDic.md +1 -1
  11. package/docs/api/functions/convertKradFile.md +1 -1
  12. package/docs/api/functions/convertRadkFile.md +1 -1
  13. package/docs/api/functions/convertTanakaCorpus.md +1 -1
  14. package/docs/api/functions/generateAnkiNote.md +1 -1
  15. package/docs/api/functions/generateAnkiNotesFile.md +3 -3
  16. package/docs/api/functions/getKanji.md +1 -1
  17. package/docs/api/functions/getKanjiExtended.md +1 -1
  18. package/docs/api/functions/getWord.md +1 -1
  19. package/docs/api/functions/isStringArray.md +1 -1
  20. package/docs/api/functions/isValidArray.md +1 -1
  21. package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
  22. package/docs/api/functions/makeSSML.md +1 -1
  23. package/docs/api/functions/shuffleArray.md +1 -1
  24. package/docs/api/functions/synthesizeSpeech.md +3 -3
  25. package/docs/api/interfaces/DictKanji.md +4 -4
  26. package/docs/api/interfaces/DictKanjiForm.md +4 -4
  27. package/docs/api/interfaces/DictKanjiMisc.md +5 -5
  28. package/docs/api/interfaces/DictKanjiReading.md +3 -3
  29. package/docs/api/interfaces/DictKanjiReadingMeaning.md +3 -3
  30. package/docs/api/interfaces/DictKanjiReadingMeaningGroup.md +3 -3
  31. package/docs/api/interfaces/DictKanjiWithRadicals.md +3 -3
  32. package/docs/api/interfaces/DictMeaning.md +11 -11
  33. package/docs/api/interfaces/DictRadical.md +4 -4
  34. package/docs/api/interfaces/DictReading.md +5 -5
  35. package/docs/api/interfaces/DictWord.md +5 -5
  36. package/docs/api/interfaces/ExamplePart.md +7 -7
  37. package/docs/api/interfaces/Grammar.md +28 -14
  38. package/docs/api/interfaces/GrammarMeaning.md +3 -3
  39. package/docs/api/interfaces/Kana.md +24 -10
  40. package/docs/api/interfaces/Kanji.md +34 -20
  41. package/docs/api/interfaces/KanjiComponent.md +3 -3
  42. package/docs/api/interfaces/KanjiForm.md +3 -3
  43. package/docs/api/interfaces/Phrase.md +4 -4
  44. package/docs/api/interfaces/Radical.md +29 -15
  45. package/docs/api/interfaces/Reading.md +4 -4
  46. package/docs/api/interfaces/ResultEntry.md +16 -6
  47. package/docs/api/interfaces/TanakaExample.md +5 -5
  48. package/docs/api/interfaces/Translation.md +3 -3
  49. package/docs/api/interfaces/UsefulRegExps.md +9 -9
  50. package/docs/api/interfaces/Word.md +38 -12
  51. package/docs/api/type-aliases/Dict.md +1 -1
  52. package/docs/api/type-aliases/DictName.md +1 -1
  53. package/docs/api/type-aliases/EntryType.md +1 -1
  54. package/docs/api/type-aliases/JLPT.md +1 -1
  55. package/docs/api/type-aliases/Result.md +1 -1
  56. package/package.json +10 -10
package/dist/index.mjs CHANGED
@@ -1538,6 +1538,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1538
1538
  } : {}
1539
1539
  };
1540
1540
  });
1541
+ let usuallyInKanaMeanings = 0;
1541
1542
  word.translations = dictWord.meanings.map((dictMeaning) => {
1542
1543
  if (!dictMeaning.translations)
1543
1544
  throw new Error(`No translations for ${dictWord.id}`);
@@ -1591,10 +1592,11 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1591
1592
  dictMeaning.info,
1592
1593
  (info) => lookupWordNote(info, notes, word.tags, false, info)
1593
1594
  );
1594
- wordAddNoteArray(
1595
- dictMeaning.misc,
1596
- (misc) => lookupWordNote(misc, notes, word.tags, false, misc)
1597
- );
1595
+ wordAddNoteArray(dictMeaning.misc, (misc) => {
1596
+ lookupWordNote(misc, notes, word.tags, false, misc);
1597
+ if (misc.toLowerCase() === "word usually written using kana alone")
1598
+ usuallyInKanaMeanings++;
1599
+ });
1598
1600
  for (let i = 0; i < notes.length; i++)
1599
1601
  notes[i] = capitalizeString(notes[i]);
1600
1602
  return {
@@ -1602,6 +1604,8 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1602
1604
  notes
1603
1605
  };
1604
1606
  });
1607
+ if (word.translations && word.translations.length === usuallyInKanaMeanings)
1608
+ word.usuallyInKana = true;
1605
1609
  if (kanjiDic && word.kanjiForms) {
1606
1610
  word.kanji = [];
1607
1611
  for (const kanjiForm of word.kanjiForms)
@@ -1675,11 +1679,17 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1675
1679
  ];
1676
1680
  }
1677
1681
  }
1678
- word.phrases = (examples.length > 5 ? examples.slice(0, 5) : examples).map((ex) => ({
1679
- phrase: ex.furigana ?? ex.phrase,
1680
- translation: ex.translation,
1681
- originalPhrase: ex.phrase
1682
- }));
1682
+ examples = examples.filter(
1683
+ (example, index, arr) => arr.findIndex(
1684
+ (ex) => ex.phrase === example.phrase
1685
+ ) === index
1686
+ );
1687
+ if (examples.length > 0)
1688
+ word.phrases = (examples.length > 5 ? examples.slice(0, 5) : examples).map((ex) => ({
1689
+ phrase: ex.furigana ?? ex.phrase,
1690
+ translation: ex.translation,
1691
+ originalPhrase: ex.phrase
1692
+ }));
1683
1693
  }
1684
1694
  return word;
1685
1695
  } else throw new Error(`Word${id ? ` ${id}` : ""} not found`);
@@ -1973,11 +1983,8 @@ function generateAnkiNote(entry) {
1973
1983
  const fields = [];
1974
1984
  if (isWord(entry)) {
1975
1985
  if (!entry.translations) throw new Error(`Invalid word: ${entry.noteID}`);
1976
- const usuallyInKana = entry.translations.every(
1977
- (translation) => translation.notes && translation.notes.includes("Word usually written using kana alone")
1978
- );
1979
1986
  fields.push(
1980
- ...entry.kanjiForms && !usuallyInKana ? [
1987
+ ...entry.kanjiForms && !entry.usuallyInKana ? [
1981
1988
  entry.kanjiForms.map(
1982
1989
  (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>" : ""}`
1983
1990
  ).join(""),
@@ -2152,7 +2159,7 @@ function generateAnkiNotesFile(list) {
2152
2159
  "#notetype column:2",
2153
2160
  "#deck column:3"
2154
2161
  ];
2155
- const ankiNotes = list.map((result) => {
2162
+ const ankiNotes = list.filter((result) => result.doNotCreateNote === void 0).map((result) => {
2156
2163
  if (!result.noteID || !result.noteTypeName || !result.deckPath)
2157
2164
  throw new Error("Invalid result");
2158
2165
  const note = generateAnkiNote(result);