henkan 0.1.3 → 0.2.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 (58) hide show
  1. package/dist/index.cjs.js +94 -57
  2. package/dist/index.cjs.js.map +3 -3
  3. package/dist/index.mjs +92 -57
  4. package/dist/index.mjs.map +3 -3
  5. package/dist/types/types.d.ts +24 -3
  6. package/dist/types/types.d.ts.map +1 -1
  7. package/dist/types/utils.d.ts.map +1 -1
  8. package/docs/api/README.md +1 -0
  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 +14 -4
  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 +8 -8
  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 +31 -21
  42. package/docs/api/interfaces/KanjiComponent.md +3 -3
  43. package/docs/api/interfaces/KanjiForm.md +3 -3
  44. package/docs/api/interfaces/NoteAndTag.md +31 -0
  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 +4 -4
  48. package/docs/api/interfaces/ResultEntry.md +7 -7
  49. package/docs/api/interfaces/TanakaExample.md +7 -7
  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 +3 -3
package/dist/index.mjs CHANGED
@@ -1343,8 +1343,11 @@ function convertKanjiDic(xmlString) {
1343
1343
  }
1344
1344
  if (isValidArray(group.meaning)) {
1345
1345
  for (const meaning of group.meaning)
1346
- if (typeof meaning === "string")
1346
+ if (typeof meaning === "string") {
1347
+ if (kanjiObj.isKokuji === void 0 && meaning === "(kokuji)")
1348
+ kanjiObj.isKokuji = true;
1347
1349
  groupObj.meanings.push(meaning);
1350
+ }
1348
1351
  }
1349
1352
  if (groupObj.readings.length > 0 || groupObj.meanings.length > 0)
1350
1353
  rmObj.groups.push(groupObj);
@@ -1526,11 +1529,12 @@ function lookupWordNote(key, notes, tags, required, fallback) {
1526
1529
  );
1527
1530
  if (!info) {
1528
1531
  if (required) throw new Error(`Invalid note info for ${key}`);
1529
- notes.push(fallback ?? key);
1530
- return;
1532
+ if (notes) notes.push(fallback ?? key);
1533
+ return { note: fallback ?? key };
1531
1534
  }
1532
- tags.push(info[0]);
1533
- notes.push(info[1]);
1535
+ if (tags) tags.push(`word::${info[0]}`);
1536
+ if (notes) notes.push(info[1]);
1537
+ return { note: info[1], tag: `word::${info[0]}` };
1534
1538
  }
1535
1539
  var wordAddNoteArray = (arr, cb) => {
1536
1540
  if (!arr) return;
@@ -1547,40 +1551,48 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1547
1551
  translations: [],
1548
1552
  noteID: `word_${dictWord.id}`,
1549
1553
  ...noteTypeName ? { noteTypeName } : {},
1550
- ...deckPath ? { deckPath } : {}
1554
+ ...deckPath ? { deckPath } : {},
1555
+ tags: []
1551
1556
  };
1557
+ if (dictWord.isCommon === true) word.common = true;
1552
1558
  if (dictWord.kanjiForms)
1553
1559
  word.kanjiForms = dictWord.kanjiForms.map(
1554
- (dictKanjiForm) => {
1555
- if (dictKanjiForm.commonness && dictKanjiForm.commonness.length > 0 && word.common === void 0)
1556
- word.common = true;
1557
- return {
1558
- kanjiForm: dictKanjiForm.form,
1559
- ...dictKanjiForm.notes ? {
1560
- notes: dictKanjiForm.notes.map(
1561
- (note) => capitalizeString(note)
1562
- )
1563
- } : {}
1564
- };
1565
- }
1560
+ (dictKanjiForm) => ({
1561
+ kanjiForm: dictKanjiForm.form,
1562
+ ...dictKanjiForm.notes ? {
1563
+ notes: dictKanjiForm.notes.map((note) => {
1564
+ const noteAndTag = lookupWordNote(
1565
+ note,
1566
+ void 0,
1567
+ word.tags,
1568
+ false,
1569
+ note
1570
+ );
1571
+ return capitalizeString(noteAndTag.note ?? note);
1572
+ })
1573
+ } : {}
1574
+ })
1566
1575
  );
1567
- word.readings = dictWord.readings.map((dictReading) => {
1568
- if (dictReading.commonness && dictReading.commonness.length > 0 && word.common === void 0)
1569
- word.common = true;
1570
- return {
1571
- reading: dictReading.reading,
1572
- ...dictReading.kanjiFormRestrictions || dictReading.notes ? {
1573
- notes: [
1574
- ...dictReading.kanjiFormRestrictions ? dictReading.kanjiFormRestrictions.map(
1575
- (restriction) => `Reading restricted to ${restriction}`
1576
- ) : [],
1577
- ...dictReading.notes ? dictReading.notes.map(
1578
- (note) => capitalizeString(note)
1579
- ) : []
1580
- ]
1581
- } : {}
1582
- };
1583
- });
1576
+ word.readings = dictWord.readings.map((dictReading) => ({
1577
+ reading: dictReading.reading,
1578
+ ...dictReading.kanjiFormRestrictions || dictReading.notes ? {
1579
+ notes: [
1580
+ ...dictReading.kanjiFormRestrictions ? dictReading.kanjiFormRestrictions.map(
1581
+ (restriction) => `Reading restricted to ${restriction}`
1582
+ ) : [],
1583
+ ...dictReading.notes ? dictReading.notes.map((note) => {
1584
+ const noteAndTag = lookupWordNote(
1585
+ note,
1586
+ void 0,
1587
+ word.tags,
1588
+ false,
1589
+ note
1590
+ );
1591
+ return capitalizeString(noteAndTag.note ?? note);
1592
+ }) : []
1593
+ ]
1594
+ } : {}
1595
+ }));
1584
1596
  let usuallyInKanaMeanings = 0;
1585
1597
  word.translations = dictWord.meanings.map((dictMeaning) => {
1586
1598
  if (!dictMeaning.translations)
@@ -1601,7 +1613,6 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1601
1613
  }
1602
1614
  );
1603
1615
  const notes = [];
1604
- word.tags = [];
1605
1616
  wordAddNoteArray(
1606
1617
  dictMeaning.kanjiFormRestrictions,
1607
1618
  (restriction) => notes.push(`Meaning restricted to ${restriction}`)
@@ -1672,7 +1683,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1672
1683
  }
1673
1684
  if (word.kanji.length === 0) delete word.kanji;
1674
1685
  }
1675
- if (examples) {
1686
+ if (examples && dictWord.hasPhrases === true) {
1676
1687
  const readings = new Set(
1677
1688
  word.readings.filter(
1678
1689
  (reading) => !reading.notes || reading.notes && !reading.notes.some(
@@ -1741,6 +1752,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1741
1752
  }
1742
1753
  }
1743
1754
  function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
1755
+ var _a, _b, _c, _d;
1744
1756
  try {
1745
1757
  const dictKanji = dict.find(
1746
1758
  (entry) => entry.kanji === kanjiChar
@@ -1855,26 +1867,35 @@ function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
1855
1867
  let codePoint = kanji.kanji.codePointAt(0);
1856
1868
  if (codePoint !== void 0) {
1857
1869
  codePoint = codePoint.toString(16);
1870
+ const fileNames = [
1871
+ `0${codePoint}.svg`,
1872
+ `${codePoint}.svg`
1873
+ ];
1858
1874
  const svg = svgList.find(
1859
- (svgFile) => svgFile.toLowerCase() === `0${codePoint}.svg` || svgFile.toLowerCase() === `${codePoint}.svg`
1875
+ (svgFile) => fileNames.includes(svgFile.toLowerCase())
1860
1876
  );
1861
1877
  if (svg) kanji.svg = svg;
1862
1878
  }
1863
1879
  }
1864
1880
  kanji.tags = [];
1865
- if (kanji.meanings && kanji.meanings.some((meaning) => meaning === "(kokuji)")) {
1866
- kanji.tags.push("kokuji");
1867
- kanji.meanings = kanji.meanings.filter(
1868
- (meaning) => meaning !== "(kokuji)"
1869
- );
1881
+ if (dictKanji.isKokuji === true) {
1882
+ kanji.kokuji = true;
1883
+ kanji.tags.push("kanji::kokuji");
1884
+ if (kanji.meanings)
1885
+ kanji.meanings.splice(
1886
+ kanji.meanings.findIndex(
1887
+ (meaning) => meaning === "(kokuji)"
1888
+ ),
1889
+ 1
1890
+ );
1870
1891
  }
1871
1892
  kanji.tags.push(
1872
- ...!kanji.onyomi ? ["no::onyomi"] : [],
1873
- ...!kanji.kunyomi ? ["no::kunyomi"] : [],
1874
- ...kanji.nanori ? ["has::nanori"] : [],
1875
- ...kanji.svg ? ["has::svg"] : [],
1876
- ...kanji.strokes && kanji.strokes.length > 0 ? [`strokes::${kanji.strokes}`] : [],
1877
- ...kanji.words ? ["has::words"] : []
1893
+ `kanji::onyomi::${((_a = kanji.onyomi) == null ? void 0 : _a.length) ?? 0}`,
1894
+ `kanji::kunyomi::${((_b = kanji.kunyomi) == null ? void 0 : _b.length) ?? 0}`,
1895
+ `kanji::nanori::${((_c = kanji.nanori) == null ? void 0 : _c.length) ?? 0}`,
1896
+ `kanji::strokes::${kanji.strokes ?? "unknown"}`,
1897
+ `kanji::words::${((_d = kanji.words) == null ? void 0 : _d.length) ?? 0}`,
1898
+ ...kanji.svg ? ["kanji::has_svg"] : []
1878
1899
  );
1879
1900
  return kanji;
1880
1901
  } else throw new Error(`Kanji ${kanjiChar} not found`);
@@ -1883,6 +1904,7 @@ function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
1883
1904
  }
1884
1905
  }
1885
1906
  function getKanjiExtended(kanjiChar, info, dict, useJpdbWords, jmDict, svgList, noteTypeName, deckPath) {
1907
+ var _a, _b;
1886
1908
  try {
1887
1909
  const kanji = getKanji(
1888
1910
  kanjiChar,
@@ -1898,12 +1920,25 @@ function getKanjiExtended(kanjiChar, info, dict, useJpdbWords, jmDict, svgList,
1898
1920
  kanji.mnemonic = info.mnemonic;
1899
1921
  if (useJpdbWords === true && info.words && info.words.length > 0)
1900
1922
  kanji.words = info.words;
1901
- if (kanji.mnemonic && kanji.mnemonic.length > 0 && kanji.tags)
1902
- kanji.tags.push("has::mnemonic");
1903
- if (kanji.components && kanji.components.length > 0 && kanji.tags)
1904
- kanji.tags.push(`components::${kanji.components.length}`);
1905
- if (kanji.words && kanji.tags && !kanji.tags.includes("has::words"))
1906
- kanji.tags.push("has::words");
1923
+ if (kanji.tags) {
1924
+ kanji.tags.push(`kanji::components::${((_a = kanji.components) == null ? void 0 : _a.length) ?? 0}`);
1925
+ if (kanji.mnemonic && kanji.mnemonic.length > 0)
1926
+ kanji.tags.push("kanji::has_mnemonic");
1927
+ if (useJpdbWords === true && kanji.words) {
1928
+ if (!kanji.tags.some((tag, index) => {
1929
+ var _a2;
1930
+ if (tag.startsWith("kanji::words::")) {
1931
+ kanji.tags.splice(
1932
+ index,
1933
+ 1,
1934
+ `kanji::words::${((_a2 = kanji.words) == null ? void 0 : _a2.length) ?? 0}`
1935
+ );
1936
+ return true;
1937
+ } else return false;
1938
+ }))
1939
+ kanji.tags.push(`kanji::words::${((_b = kanji.words) == null ? void 0 : _b.length) ?? 0}`);
1940
+ }
1941
+ }
1907
1942
  if (kanji.fromJpdb === true && (kanji.mnemonic || kanji.components && kanji.components.length > 0 || kanji.words))
1908
1943
  kanji.source = `https://jpdb.io/kanji/${kanji.kanji}#a`;
1909
1944
  return kanji;
@@ -2108,12 +2143,12 @@ function generateAnkiNote(entry) {
2108
2143
  (onyomiEntry) => createEntry(
2109
2144
  `<span class="kanji kanji-onyomi">${onyomiEntry}</span>`
2110
2145
  )
2111
- ).join("") : '<span class="kanji kanji-onyomi">(no onyomi) (kokuji)</span>',
2146
+ ).join("") : `<span class="kanji kanji-onyomi">(no onyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span`,
2112
2147
  entry.kunyomi ? entry.kunyomi.map(
2113
2148
  (kunyomiEntry) => createEntry(
2114
2149
  `<span class="kanji kanji-kunyomi">${kunyomiEntry}</span>`
2115
2150
  )
2116
- ).join("") : '<span class="kanji kanji-kunyomi">(no kunyomi)</span>',
2151
+ ).join("") : `<span class="kanji kanji-kunyomi">(no kunyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
2117
2152
  entry.nanori ? entry.nanori.map(
2118
2153
  (nanoriEntry) => createEntry(
2119
2154
  `<span class="kanji kanji-nanori">${nanoriEntry}</span>`