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.
- package/dist/index.cjs.js +47 -4
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +47 -4
- package/dist/index.mjs.map +3 -3
- package/dist/types/types.d.ts +10 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +2 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/functions/capitalizeString.md +1 -1
- package/docs/api/functions/convertJMdict.md +8 -2
- package/docs/api/functions/convertKanjiDic.md +1 -1
- package/docs/api/functions/convertKradFile.md +1 -1
- package/docs/api/functions/convertRadkFile.md +1 -1
- package/docs/api/functions/convertTanakaCorpus.md +1 -1
- package/docs/api/functions/generateAnkiNote.md +1 -1
- package/docs/api/functions/generateAnkiNotesFile.md +1 -1
- package/docs/api/functions/getKanji.md +1 -1
- package/docs/api/functions/getKanjiExtended.md +1 -1
- package/docs/api/functions/getWord.md +1 -1
- package/docs/api/functions/isStringArray.md +1 -1
- package/docs/api/functions/isValidArray.md +1 -1
- package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
- package/docs/api/functions/makeSSML.md +1 -1
- package/docs/api/functions/shuffleArray.md +1 -1
- package/docs/api/functions/synthesizeSpeech.md +1 -1
- package/docs/api/interfaces/DictKanji.md +4 -4
- package/docs/api/interfaces/DictKanjiForm.md +4 -4
- package/docs/api/interfaces/DictKanjiMisc.md +5 -5
- package/docs/api/interfaces/DictKanjiReading.md +3 -3
- package/docs/api/interfaces/DictKanjiReadingMeaning.md +3 -3
- package/docs/api/interfaces/DictKanjiReadingMeaningGroup.md +3 -3
- package/docs/api/interfaces/DictKanjiWithRadicals.md +3 -3
- package/docs/api/interfaces/DictMeaning.md +11 -11
- package/docs/api/interfaces/DictRadical.md +4 -4
- package/docs/api/interfaces/DictReading.md +5 -5
- package/docs/api/interfaces/DictWord.md +27 -5
- package/docs/api/interfaces/ExamplePart.md +7 -7
- package/docs/api/interfaces/Grammar.md +15 -15
- package/docs/api/interfaces/GrammarMeaning.md +3 -3
- package/docs/api/interfaces/Kana.md +11 -11
- package/docs/api/interfaces/Kanji.md +21 -21
- package/docs/api/interfaces/KanjiComponent.md +3 -3
- package/docs/api/interfaces/KanjiForm.md +3 -3
- package/docs/api/interfaces/Phrase.md +4 -4
- package/docs/api/interfaces/Radical.md +16 -16
- package/docs/api/interfaces/Reading.md +4 -4
- package/docs/api/interfaces/ResultEntry.md +7 -7
- package/docs/api/interfaces/TanakaExample.md +5 -5
- package/docs/api/interfaces/Translation.md +3 -3
- package/docs/api/interfaces/UsefulRegExps.md +9 -9
- package/docs/api/interfaces/Word.md +14 -14
- package/docs/api/type-aliases/Dict.md +1 -1
- package/docs/api/type-aliases/DictName.md +1 -1
- package/docs/api/type-aliases/EntryType.md +1 -1
- package/docs/api/type-aliases/JLPT.md +1 -1
- package/docs/api/type-aliases/Result.md +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1203,7 +1203,7 @@ function shuffleArray(arr) {
|
|
|
1203
1203
|
}
|
|
1204
1204
|
return a;
|
|
1205
1205
|
}
|
|
1206
|
-
function convertJMdict(xmlString) {
|
|
1206
|
+
function convertJMdict(xmlString, examples) {
|
|
1207
1207
|
try {
|
|
1208
1208
|
const dictParsed = import_libxmljs2.default.parseXml(xmlString, {
|
|
1209
1209
|
dtdvalid: true,
|
|
@@ -1214,6 +1214,13 @@ function convertJMdict(xmlString) {
|
|
|
1214
1214
|
const dict = [];
|
|
1215
1215
|
import_xml2js.default.parseString(dictParsed, (err, result) => {
|
|
1216
1216
|
if (err) throw err;
|
|
1217
|
+
let tanakaBaseParts = void 0;
|
|
1218
|
+
if (examples)
|
|
1219
|
+
tanakaBaseParts = new Set(
|
|
1220
|
+
examples.map(
|
|
1221
|
+
(example) => example.parts.map((part) => part.baseForm)
|
|
1222
|
+
).flat()
|
|
1223
|
+
);
|
|
1217
1224
|
if (result.JMdict && typeof result.JMdict === "object" && isValidArray(result.JMdict.entry))
|
|
1218
1225
|
for (const entry of result.JMdict.entry) {
|
|
1219
1226
|
const entryObj = {
|
|
@@ -1237,8 +1244,10 @@ function convertJMdict(xmlString) {
|
|
|
1237
1244
|
);
|
|
1238
1245
|
if (isStringArray(kanjiForm.ke_inf))
|
|
1239
1246
|
form.notes = kanjiForm.ke_inf;
|
|
1240
|
-
if (isStringArray(kanjiForm.ke_pri))
|
|
1247
|
+
if (isStringArray(kanjiForm.ke_pri)) {
|
|
1241
1248
|
form.commonness = kanjiForm.ke_pri;
|
|
1249
|
+
if (entryObj.isCommon === void 0) entryObj.isCommon = true;
|
|
1250
|
+
}
|
|
1242
1251
|
if (form.form.length > 0) entryObj.kanjiForms.push(form);
|
|
1243
1252
|
}
|
|
1244
1253
|
}
|
|
@@ -1251,10 +1260,12 @@ function convertJMdict(xmlString) {
|
|
|
1251
1260
|
throw new Error(`Invalid JMdict entry reading: ${entryObj.id}`);
|
|
1252
1261
|
if (isStringArray(reading.re_inf))
|
|
1253
1262
|
readingObj.notes = reading.re_inf;
|
|
1254
|
-
if (isStringArray(reading.re_pri))
|
|
1255
|
-
readingObj.commonness = reading.re_pri;
|
|
1256
1263
|
if (isStringArray(reading.re_restr))
|
|
1257
1264
|
readingObj.kanjiFormRestrictions = reading.re_restr;
|
|
1265
|
+
if (isStringArray(reading.re_pri)) {
|
|
1266
|
+
readingObj.commonness = reading.re_pri;
|
|
1267
|
+
if (entryObj.isCommon === void 0) entryObj.isCommon = true;
|
|
1268
|
+
}
|
|
1258
1269
|
if (readingObj.reading.length > 0)
|
|
1259
1270
|
entryObj.readings.push(readingObj);
|
|
1260
1271
|
}
|
|
@@ -1290,6 +1301,38 @@ function convertJMdict(xmlString) {
|
|
|
1290
1301
|
if (meaningObj.partOfSpeech && meaningObj.partOfSpeech.length > 0 || meaningObj.translations && meaningObj.translations.length > 0)
|
|
1291
1302
|
entryObj.meanings.push(meaningObj);
|
|
1292
1303
|
}
|
|
1304
|
+
if (examples) {
|
|
1305
|
+
const readings2 = new Set(
|
|
1306
|
+
entryObj.readings.filter(
|
|
1307
|
+
(reading) => !reading.notes || reading.notes && !reading.notes.some(
|
|
1308
|
+
(note) => notSearchedForms.has(note)
|
|
1309
|
+
)
|
|
1310
|
+
).map((reading) => reading.reading)
|
|
1311
|
+
);
|
|
1312
|
+
const kanjiForms2 = entryObj.kanjiForms ? new Set(
|
|
1313
|
+
entryObj.kanjiForms.map(
|
|
1314
|
+
(kanjiForm) => kanjiForm.form
|
|
1315
|
+
)
|
|
1316
|
+
) : void 0;
|
|
1317
|
+
let kanjiFormExamples = false;
|
|
1318
|
+
let readingExamples = false;
|
|
1319
|
+
if (kanjiForms2 && kanjiForms2.size > 0 && tanakaBaseParts) {
|
|
1320
|
+
for (const kf of kanjiForms2)
|
|
1321
|
+
if (tanakaBaseParts.has(kf)) {
|
|
1322
|
+
kanjiFormExamples = true;
|
|
1323
|
+
break;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
if (!kanjiFormExamples && readings2.size > 0 && tanakaBaseParts) {
|
|
1327
|
+
for (const r of readings2)
|
|
1328
|
+
if (tanakaBaseParts.has(r)) {
|
|
1329
|
+
readingExamples = true;
|
|
1330
|
+
break;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (kanjiFormExamples || readingExamples)
|
|
1334
|
+
entryObj.hasPhrases = true;
|
|
1335
|
+
}
|
|
1293
1336
|
if (entryObj.id.length > 0 && entryObj.readings.length > 0 && entryObj.meanings.length > 0)
|
|
1294
1337
|
dict.push(entryObj);
|
|
1295
1338
|
}
|