henkan 0.2.0 → 0.3.0

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 (58) hide show
  1. package/dist/index.cjs.js +79 -37
  2. package/dist/index.cjs.js.map +3 -3
  3. package/dist/index.mjs +79 -37
  4. package/dist/index.mjs.map +3 -3
  5. package/dist/types/constants.d.ts.map +1 -1
  6. package/dist/types/types.d.ts +8 -0
  7. package/dist/types/types.d.ts.map +1 -1
  8. package/dist/types/utils.d.ts.map +1 -1
  9. package/docs/api/functions/capitalizeString.md +1 -1
  10. package/docs/api/functions/convertJMdict.md +1 -1
  11. package/docs/api/functions/convertKanjiDic.md +1 -1
  12. package/docs/api/functions/convertKradFile.md +1 -1
  13. package/docs/api/functions/convertRadkFile.md +1 -1
  14. package/docs/api/functions/convertTanakaCorpus.md +1 -1
  15. package/docs/api/functions/generateAnkiNote.md +1 -1
  16. package/docs/api/functions/generateAnkiNotesFile.md +1 -1
  17. package/docs/api/functions/getKanji.md +1 -1
  18. package/docs/api/functions/getKanjiExtended.md +1 -1
  19. package/docs/api/functions/getWord.md +1 -1
  20. package/docs/api/functions/isStringArray.md +1 -1
  21. package/docs/api/functions/isValidArray.md +1 -1
  22. package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
  23. package/docs/api/functions/makeSSML.md +1 -1
  24. package/docs/api/functions/shuffleArray.md +1 -1
  25. package/docs/api/functions/synthesizeSpeech.md +1 -1
  26. package/docs/api/interfaces/DictKanji.md +5 -5
  27. package/docs/api/interfaces/DictKanjiForm.md +4 -4
  28. package/docs/api/interfaces/DictKanjiMisc.md +5 -5
  29. package/docs/api/interfaces/DictKanjiReading.md +3 -3
  30. package/docs/api/interfaces/DictKanjiReadingMeaning.md +3 -3
  31. package/docs/api/interfaces/DictKanjiReadingMeaningGroup.md +3 -3
  32. package/docs/api/interfaces/DictKanjiWithRadicals.md +3 -3
  33. package/docs/api/interfaces/DictMeaning.md +11 -11
  34. package/docs/api/interfaces/DictRadical.md +4 -4
  35. package/docs/api/interfaces/DictReading.md +5 -5
  36. package/docs/api/interfaces/DictWord.md +7 -7
  37. package/docs/api/interfaces/ExamplePart.md +7 -7
  38. package/docs/api/interfaces/Grammar.md +15 -15
  39. package/docs/api/interfaces/GrammarMeaning.md +3 -3
  40. package/docs/api/interfaces/Kana.md +11 -11
  41. package/docs/api/interfaces/Kanji.md +22 -22
  42. package/docs/api/interfaces/KanjiComponent.md +3 -3
  43. package/docs/api/interfaces/KanjiForm.md +13 -3
  44. package/docs/api/interfaces/NoteAndTag.md +3 -3
  45. package/docs/api/interfaces/Phrase.md +4 -4
  46. package/docs/api/interfaces/Radical.md +16 -16
  47. package/docs/api/interfaces/Reading.md +14 -4
  48. package/docs/api/interfaces/ResultEntry.md +7 -7
  49. package/docs/api/interfaces/TanakaExample.md +5 -5
  50. package/docs/api/interfaces/Translation.md +3 -3
  51. package/docs/api/interfaces/UsefulRegExps.md +9 -9
  52. package/docs/api/interfaces/Word.md +14 -14
  53. package/docs/api/type-aliases/Dict.md +1 -1
  54. package/docs/api/type-aliases/DictName.md +1 -1
  55. package/docs/api/type-aliases/EntryType.md +1 -1
  56. package/docs/api/type-aliases/JLPT.md +1 -1
  57. package/docs/api/type-aliases/Result.md +1 -1
  58. package/package.json +8 -8
package/dist/index.cjs.js CHANGED
@@ -121,10 +121,21 @@ var symbolMap = {
121
121
  "&": "\u30A2\u30F3\u30C9"
122
122
  };
123
123
  var notSearchedForms = /* @__PURE__ */ new Set([
124
+ "search-only kana form",
124
125
  "Search-only kana form",
126
+ "rarely used kana form",
125
127
  "Rarely used kana form",
128
+ "out-dated or obsolete kana usage",
126
129
  "Out-dated or obsolete kana usage",
127
- "Word containing out-dated kanji or kanji usage"
130
+ "search-only kanji form",
131
+ "Search-only kanji form",
132
+ "rarely-used kanji form",
133
+ "Rarely-used kanji form",
134
+ "out-dated kanji",
135
+ "Out-dated kanji form",
136
+ "out-dated kanji or kanji usage",
137
+ "word containing out-dated kanji or kanji usage",
138
+ "Out-dated kanji or kanji usage"
128
139
  ]);
129
140
  var noteMap = /* @__PURE__ */ new Map([
130
141
  ["brazilian", ["dialect::brazilian", "Dialect: Brazilian"]],
@@ -1304,15 +1315,17 @@ function convertJMdict(xmlString, examples) {
1304
1315
  if (examples) {
1305
1316
  const readings2 = new Set(
1306
1317
  entryObj.readings.filter(
1307
- (reading) => !reading.notes || reading.notes && !reading.notes.some(
1318
+ (reading) => !reading.notes || !reading.notes.some(
1308
1319
  (note) => notSearchedForms.has(note)
1309
1320
  )
1310
1321
  ).map((reading) => reading.reading)
1311
1322
  );
1312
1323
  const kanjiForms2 = entryObj.kanjiForms ? new Set(
1313
- entryObj.kanjiForms.map(
1314
- (kanjiForm) => kanjiForm.form
1315
- )
1324
+ entryObj.kanjiForms.filter(
1325
+ (kanjiForm) => !kanjiForm.notes || !kanjiForm.notes.some(
1326
+ (note) => notSearchedForms.has(note)
1327
+ )
1328
+ ).map((kanjiForm) => kanjiForm.form)
1316
1329
  ) : void 0;
1317
1330
  let kanjiFormExamples = false;
1318
1331
  let readingExamples = false;
@@ -1323,7 +1336,7 @@ function convertJMdict(xmlString, examples) {
1323
1336
  break;
1324
1337
  }
1325
1338
  }
1326
- if (!kanjiFormExamples && readings2.size > 0 && tanakaBaseParts) {
1339
+ if ((!kanjiFormExamples || entryObj.isCommon === true) && readings2.size > 0 && tanakaBaseParts) {
1327
1340
  for (const r of readings2)
1328
1341
  if (tanakaBaseParts.has(r)) {
1329
1342
  readingExamples = true;
@@ -1625,7 +1638,8 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1625
1638
  );
1626
1639
  return capitalizeString((_a = noteAndTag.note) != null ? _a : note);
1627
1640
  })
1628
- } : {}
1641
+ } : {},
1642
+ ...dictKanjiForm.commonness && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
1629
1643
  })
1630
1644
  );
1631
1645
  word.readings = dictWord.readings.map((dictReading) => ({
@@ -1647,7 +1661,8 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1647
1661
  return capitalizeString((_a = noteAndTag.note) != null ? _a : note);
1648
1662
  }) : []
1649
1663
  ]
1650
- } : {}
1664
+ } : {},
1665
+ ...dictReading.commonness && dictReading.commonness.length > 0 ? { common: true } : {}
1651
1666
  }));
1652
1667
  let usuallyInKanaMeanings = 0;
1653
1668
  word.translations = dictWord.meanings.map((dictMeaning) => {
@@ -1740,36 +1755,61 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1740
1755
  if (word.kanji.length === 0) delete word.kanji;
1741
1756
  }
1742
1757
  if (examples && dictWord.hasPhrases === true) {
1758
+ let pushIfUnique2 = function(ex) {
1759
+ if (!seenPhrases.has(ex.phrase)) {
1760
+ wordExamples.push(ex);
1761
+ seenPhrases.add(ex.phrase);
1762
+ }
1763
+ };
1764
+ var pushIfUnique = pushIfUnique2;
1743
1765
  const readings = new Set(
1744
1766
  word.readings.filter(
1745
- (reading) => !reading.notes || reading.notes && !reading.notes.some(
1767
+ (reading) => (!reading.notes || !reading.notes.some(
1746
1768
  (note) => notSearchedForms.has(note)
1747
- )
1769
+ )) && (word.common === void 0 || reading.common === true)
1748
1770
  ).map((reading) => reading.reading)
1749
1771
  );
1750
1772
  const kanjiForms = word.kanjiForms ? new Set(
1751
- word.kanjiForms.map(
1752
- (kanjiForm) => kanjiForm.kanjiForm
1753
- )
1773
+ word.kanjiForms.filter(
1774
+ (kanjiForm) => (!kanjiForm.notes || !kanjiForm.notes.some(
1775
+ (note) => notSearchedForms.has(note)
1776
+ )) && (word.common === void 0 || kanjiForm.common === true)
1777
+ ).map((kanjiForm) => kanjiForm.kanjiForm)
1754
1778
  ) : void 0;
1755
1779
  const kanjiFormExamples = [];
1780
+ const readingMatchingKanjiFormExamples = [];
1756
1781
  const readingExamples = [];
1757
- if (kanjiForms) {
1758
- for (const example of examples)
1759
- for (const part of example.parts)
1760
- if (kanjiForms.has(part.baseForm))
1761
- kanjiFormExamples.push(example);
1762
- }
1763
- if (kanjiFormExamples.length === 0) {
1764
- for (const example of examples)
1765
- for (const part of example.parts)
1766
- if (readings.has(part.baseForm)) readingExamples.push(example);
1767
- }
1768
- examples = [...kanjiFormExamples, ...readingExamples];
1782
+ for (const example of examples)
1783
+ for (const part of example.parts) {
1784
+ const readingMatch = part.reading && readings.has(part.reading) || readings.has(part.baseForm);
1785
+ if (kanjiForms && kanjiForms.size > 0 && kanjiForms.has(part.baseForm)) {
1786
+ if (readingMatch) readingMatchingKanjiFormExamples.push(example);
1787
+ else kanjiFormExamples.push(example);
1788
+ break;
1789
+ }
1790
+ if (readingMatch || part.referenceID && word.id && part.referenceID === word.id) {
1791
+ readingExamples.push(example);
1792
+ break;
1793
+ }
1794
+ }
1795
+ const exampleSize = (/* @__PURE__ */ new Set([
1796
+ ...readingMatchingKanjiFormExamples,
1797
+ ...kanjiFormExamples,
1798
+ ...readingExamples
1799
+ ])).size;
1800
+ const includeKanjiFormExamples = readingMatchingKanjiFormExamples.length < Math.max(2, Math.round(exampleSize * 0.05));
1801
+ const includeReadingExamples = word.usuallyInKana === void 0 && includeKanjiFormExamples && readingExamples.length >= Math.max(10, Math.round(exampleSize * 0.15)) || word.usuallyInKana === true && readingExamples.length >= Math.max(2, Math.round(exampleSize * 0.5));
1802
+ const seenPhrases = /* @__PURE__ */ new Set();
1803
+ let wordExamples = [];
1804
+ for (const ex of readingMatchingKanjiFormExamples) pushIfUnique2(ex);
1805
+ if (includeKanjiFormExamples)
1806
+ for (const ex of kanjiFormExamples) pushIfUnique2(ex);
1807
+ if (includeReadingExamples)
1808
+ for (const ex of readingExamples) pushIfUnique2(ex);
1769
1809
  if (word.translations) {
1770
1810
  const glossSpecificExamples = [];
1771
1811
  for (let i = 0; i < word.translations.length; i++) {
1772
- outer: for (const example of examples)
1812
+ outer: for (const example of wordExamples)
1773
1813
  for (const part of example.parts)
1774
1814
  if (part.glossNumber === i + 1) {
1775
1815
  glossSpecificExamples.push(example);
@@ -1778,24 +1818,19 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1778
1818
  if (glossSpecificExamples.length === 5) break;
1779
1819
  }
1780
1820
  if (glossSpecificExamples.length === 5)
1781
- examples = glossSpecificExamples;
1821
+ wordExamples = glossSpecificExamples;
1782
1822
  else if (glossSpecificExamples.length > 0) {
1783
- const seenPhrases = new Set(
1823
+ const seenPhrases2 = new Set(
1784
1824
  glossSpecificExamples.map((ex) => ex.phrase)
1785
1825
  );
1786
- examples = [
1826
+ wordExamples = [
1787
1827
  ...glossSpecificExamples,
1788
- ...examples.filter((ex) => !seenPhrases.has(ex.phrase)).slice(0, 5 - glossSpecificExamples.length)
1828
+ ...wordExamples.filter((ex) => !seenPhrases2.has(ex.phrase)).slice(0, 5 - glossSpecificExamples.length)
1789
1829
  ];
1790
1830
  }
1791
1831
  }
1792
- examples = examples.filter(
1793
- (example, index, arr) => arr.findIndex(
1794
- (ex) => ex.phrase === example.phrase
1795
- ) === index
1796
- );
1797
- if (examples.length > 0)
1798
- word.phrases = (examples.length > 5 ? examples.slice(0, 5) : examples).map((ex) => {
1832
+ if (wordExamples.length > 0)
1833
+ word.phrases = (wordExamples.length > 5 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => {
1799
1834
  var _a;
1800
1835
  return {
1801
1836
  phrase: (_a = ex.furigana) != null ? _a : ex.phrase,
@@ -1940,6 +1975,13 @@ function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
1940
1975
  if (dictKanji.isKokuji === true) {
1941
1976
  kanji.kokuji = true;
1942
1977
  kanji.tags.push("kanji::kokuji");
1978
+ if (kanji.meanings)
1979
+ kanji.meanings.splice(
1980
+ kanji.meanings.findIndex(
1981
+ (meaning) => meaning === "(kokuji)"
1982
+ ),
1983
+ 1
1984
+ );
1943
1985
  }
1944
1986
  kanji.tags.push(
1945
1987
  `kanji::onyomi::${(_b = (_a = kanji.onyomi) == null ? void 0 : _a.length) != null ? _b : 0}`,