henkan 0.1.1 → 0.1.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 (57) hide show
  1. package/dist/index.cjs.js +47 -4
  2. package/dist/index.cjs.js.map +3 -3
  3. package/dist/index.mjs +47 -4
  4. package/dist/index.mjs.map +3 -3
  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 +2 -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 +8 -2
  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 +4 -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 +27 -5
  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 +21 -21
  42. package/docs/api/interfaces/KanjiComponent.md +3 -3
  43. package/docs/api/interfaces/KanjiForm.md +3 -3
  44. package/docs/api/interfaces/Phrase.md +4 -4
  45. package/docs/api/interfaces/Radical.md +16 -16
  46. package/docs/api/interfaces/Reading.md +4 -4
  47. package/docs/api/interfaces/ResultEntry.md +7 -7
  48. package/docs/api/interfaces/TanakaExample.md +5 -5
  49. package/docs/api/interfaces/Translation.md +3 -3
  50. package/docs/api/interfaces/UsefulRegExps.md +9 -9
  51. package/docs/api/interfaces/Word.md +14 -14
  52. package/docs/api/type-aliases/Dict.md +1 -1
  53. package/docs/api/type-aliases/DictName.md +1 -1
  54. package/docs/api/type-aliases/EntryType.md +1 -1
  55. package/docs/api/type-aliases/JLPT.md +1 -1
  56. package/docs/api/type-aliases/Result.md +1 -1
  57. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1149,7 +1149,7 @@ function shuffleArray(arr) {
1149
1149
  }
1150
1150
  return a;
1151
1151
  }
1152
- function convertJMdict(xmlString) {
1152
+ function convertJMdict(xmlString, examples) {
1153
1153
  try {
1154
1154
  const dictParsed = libxml.parseXml(xmlString, {
1155
1155
  dtdvalid: true,
@@ -1160,6 +1160,13 @@ function convertJMdict(xmlString) {
1160
1160
  const dict = [];
1161
1161
  xml.parseString(dictParsed, (err, result) => {
1162
1162
  if (err) throw err;
1163
+ let tanakaBaseParts = void 0;
1164
+ if (examples)
1165
+ tanakaBaseParts = new Set(
1166
+ examples.map(
1167
+ (example) => example.parts.map((part) => part.baseForm)
1168
+ ).flat()
1169
+ );
1163
1170
  if (result.JMdict && typeof result.JMdict === "object" && isValidArray(result.JMdict.entry))
1164
1171
  for (const entry of result.JMdict.entry) {
1165
1172
  const entryObj = {
@@ -1183,8 +1190,10 @@ function convertJMdict(xmlString) {
1183
1190
  );
1184
1191
  if (isStringArray(kanjiForm.ke_inf))
1185
1192
  form.notes = kanjiForm.ke_inf;
1186
- if (isStringArray(kanjiForm.ke_pri))
1193
+ if (isStringArray(kanjiForm.ke_pri)) {
1187
1194
  form.commonness = kanjiForm.ke_pri;
1195
+ if (entryObj.isCommon === void 0) entryObj.isCommon = true;
1196
+ }
1188
1197
  if (form.form.length > 0) entryObj.kanjiForms.push(form);
1189
1198
  }
1190
1199
  }
@@ -1197,10 +1206,12 @@ function convertJMdict(xmlString) {
1197
1206
  throw new Error(`Invalid JMdict entry reading: ${entryObj.id}`);
1198
1207
  if (isStringArray(reading.re_inf))
1199
1208
  readingObj.notes = reading.re_inf;
1200
- if (isStringArray(reading.re_pri))
1201
- readingObj.commonness = reading.re_pri;
1202
1209
  if (isStringArray(reading.re_restr))
1203
1210
  readingObj.kanjiFormRestrictions = reading.re_restr;
1211
+ if (isStringArray(reading.re_pri)) {
1212
+ readingObj.commonness = reading.re_pri;
1213
+ if (entryObj.isCommon === void 0) entryObj.isCommon = true;
1214
+ }
1204
1215
  if (readingObj.reading.length > 0)
1205
1216
  entryObj.readings.push(readingObj);
1206
1217
  }
@@ -1236,6 +1247,38 @@ function convertJMdict(xmlString) {
1236
1247
  if (meaningObj.partOfSpeech && meaningObj.partOfSpeech.length > 0 || meaningObj.translations && meaningObj.translations.length > 0)
1237
1248
  entryObj.meanings.push(meaningObj);
1238
1249
  }
1250
+ if (examples) {
1251
+ const readings2 = new Set(
1252
+ entryObj.readings.filter(
1253
+ (reading) => !reading.notes || reading.notes && !reading.notes.some(
1254
+ (note) => notSearchedForms.has(note)
1255
+ )
1256
+ ).map((reading) => reading.reading)
1257
+ );
1258
+ const kanjiForms2 = entryObj.kanjiForms ? new Set(
1259
+ entryObj.kanjiForms.map(
1260
+ (kanjiForm) => kanjiForm.form
1261
+ )
1262
+ ) : void 0;
1263
+ let kanjiFormExamples = false;
1264
+ let readingExamples = false;
1265
+ if (kanjiForms2 && kanjiForms2.size > 0 && tanakaBaseParts) {
1266
+ for (const kf of kanjiForms2)
1267
+ if (tanakaBaseParts.has(kf)) {
1268
+ kanjiFormExamples = true;
1269
+ break;
1270
+ }
1271
+ }
1272
+ if (!kanjiFormExamples && readings2.size > 0 && tanakaBaseParts) {
1273
+ for (const r of readings2)
1274
+ if (tanakaBaseParts.has(r)) {
1275
+ readingExamples = true;
1276
+ break;
1277
+ }
1278
+ }
1279
+ if (kanjiFormExamples || readingExamples)
1280
+ entryObj.hasPhrases = true;
1281
+ }
1239
1282
  if (entryObj.id.length > 0 && entryObj.readings.length > 0 && entryObj.meanings.length > 0)
1240
1283
  dict.push(entryObj);
1241
1284
  }