henkan 2.4.11 → 2.4.12
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 +49 -43
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.mjs +49 -43
- package/dist/index.mjs.map +2 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/functions/generateAnkiNote.md +1 -1
- package/docs/api/functions/generateAnkiNotesFile.md +1 -1
- package/package.json +1 -1
- package/src/utils.ts +136 -84
package/dist/index.mjs
CHANGED
|
@@ -2449,17 +2449,34 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2449
2449
|
...dictReading.commonness !== void 0 && dictReading.commonness.length > 0 ? { common: true } : {}
|
|
2450
2450
|
}));
|
|
2451
2451
|
word.translations = [];
|
|
2452
|
+
const meanings = dictWord.hasPhrases === true && examples !== void 0 ? [] : void 0;
|
|
2453
|
+
const seenPhrases = /* @__PURE__ */ new Set();
|
|
2452
2454
|
for (const dictMeaning of dictWord.meanings) {
|
|
2453
2455
|
const translationTypes = [];
|
|
2454
2456
|
const translations = dictMeaning.translations.map(
|
|
2455
2457
|
(translation) => {
|
|
2456
|
-
if (typeof translation === "string")
|
|
2457
|
-
|
|
2458
|
+
if (typeof translation === "string") {
|
|
2459
|
+
if (meanings !== void 0) {
|
|
2460
|
+
const cleanTranslation = translation.replaceAll(/\([^)]*\)|\[[^\]]*\]|\{[^}]*\}/g, "").trim();
|
|
2461
|
+
if (!seenPhrases.has(cleanTranslation)) {
|
|
2462
|
+
seenPhrases.add(cleanTranslation);
|
|
2463
|
+
meanings.push(cleanTranslation);
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
return translation;
|
|
2467
|
+
} else {
|
|
2458
2468
|
const translationNoteAndTag = noteMap.get(
|
|
2459
2469
|
translation.type
|
|
2460
2470
|
);
|
|
2461
2471
|
translationTypes.push(translationNoteAndTag[1]);
|
|
2462
2472
|
word.tags.push(`word::${translationNoteAndTag[0]}`);
|
|
2473
|
+
if (meanings !== void 0) {
|
|
2474
|
+
const cleanTranslation = translation.translation.replaceAll(/\([^)]*\)|\[[^\]]*\]|\{[^}]*\}/g, "").trim();
|
|
2475
|
+
if (!seenPhrases.has(cleanTranslation)) {
|
|
2476
|
+
seenPhrases.add(cleanTranslation);
|
|
2477
|
+
meanings.push(cleanTranslation);
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2463
2480
|
return translation.translation;
|
|
2464
2481
|
}
|
|
2465
2482
|
}
|
|
@@ -2513,6 +2530,7 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2513
2530
|
word.usuallyInKana = true;
|
|
2514
2531
|
word.tags.push("word::usually_in_kana_for_all_senses");
|
|
2515
2532
|
}
|
|
2533
|
+
seenPhrases.clear();
|
|
2516
2534
|
if (kanjiDic !== void 0 && word.kanjiForms !== void 0) {
|
|
2517
2535
|
const kanji = [];
|
|
2518
2536
|
const seenChars = /* @__PURE__ */ new Set();
|
|
@@ -2533,7 +2551,7 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2533
2551
|
}
|
|
2534
2552
|
if (kanji.length > 0) word.kanji = kanji;
|
|
2535
2553
|
}
|
|
2536
|
-
if (
|
|
2554
|
+
if (meanings !== void 0) {
|
|
2537
2555
|
const exampleList = examples instanceof Map ? examples.get(dictWord.id) ?? [] : examples;
|
|
2538
2556
|
const rkf = getValidForms(
|
|
2539
2557
|
dictWord.readings,
|
|
@@ -2544,22 +2562,10 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2544
2562
|
rkf.readings.map((r) => r.reading)
|
|
2545
2563
|
);
|
|
2546
2564
|
const kanjiForms = rkf.kanjiForms !== void 0 ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
|
|
2547
|
-
const meanings = new Set(
|
|
2548
|
-
dictWord.meanings.flatMap(
|
|
2549
|
-
(m) => m.translations.map((t) => {
|
|
2550
|
-
if (typeof t === "string")
|
|
2551
|
-
return t.replaceAll(/\([^)]*\)|\[[^\]]*\]|\{[^}]*\}/g, "").trim();
|
|
2552
|
-
else
|
|
2553
|
-
return t.translation.replaceAll(/\([^)]*\)|\[[^\]]*\]|\{[^}]*\}/g, "").trim();
|
|
2554
|
-
})
|
|
2555
|
-
)
|
|
2556
|
-
).values().toArray();
|
|
2557
|
-
let kanjiFormExamples = [];
|
|
2558
2565
|
let readingMatchingKanjiFormExamples = [];
|
|
2566
|
+
let kanjiFormExamples = [];
|
|
2559
2567
|
let readingExamples = [];
|
|
2560
|
-
let
|
|
2561
|
-
const readingMatchingKanjiFormsWithTranslations = /* @__PURE__ */ new Set();
|
|
2562
|
-
const seenPhrases = /* @__PURE__ */ new Set();
|
|
2568
|
+
let hasReadingMatchingKanjiFormWithTranslation = false;
|
|
2563
2569
|
for (const example of exampleList)
|
|
2564
2570
|
for (let i = 0; i < example.parts.length; i++) {
|
|
2565
2571
|
if (seenPhrases.has(example.phrase)) break;
|
|
@@ -2576,11 +2582,11 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2576
2582
|
ex: example,
|
|
2577
2583
|
partIndex: i,
|
|
2578
2584
|
form: part.baseForm,
|
|
2585
|
+
...referenceIDMatch ? { referenceIDMatch: true } : {},
|
|
2579
2586
|
...includesTranslation ? { includesTranslation: true } : {}
|
|
2580
2587
|
});
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
readingMatchingKanjiFormsWithTranslations.add(part.baseForm);
|
|
2588
|
+
if (!hasReadingMatchingKanjiFormWithTranslation && includesTranslation)
|
|
2589
|
+
hasReadingMatchingKanjiFormWithTranslation = true;
|
|
2584
2590
|
} else
|
|
2585
2591
|
kanjiFormExamples.push({
|
|
2586
2592
|
ex: example,
|
|
@@ -2597,28 +2603,28 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2597
2603
|
ex: example,
|
|
2598
2604
|
partIndex: i,
|
|
2599
2605
|
...referenceIDMatch ? { referenceIDMatch: true } : {},
|
|
2600
|
-
|
|
2606
|
+
...includesTranslation ? { includesTranslation: true } : {}
|
|
2601
2607
|
});
|
|
2602
2608
|
seenPhrases.add(example.phrase);
|
|
2603
2609
|
break;
|
|
2604
2610
|
}
|
|
2605
2611
|
}
|
|
2606
|
-
if (
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2612
|
+
if (readingMatchingKanjiFormExamples.length > 0) {
|
|
2613
|
+
if (hasReadingMatchingKanjiFormWithTranslation)
|
|
2614
|
+
readingMatchingKanjiFormExamples = readingMatchingKanjiFormExamples.filter(
|
|
2615
|
+
(ex) => ex.includesTranslation === true || ex.referenceIDMatch === true || ex.ex.parts.some(
|
|
2616
|
+
(part) => ex.form === part.baseForm && part.glossNumber !== void 0
|
|
2617
|
+
)
|
|
2618
|
+
);
|
|
2619
|
+
kanjiFormExamples.length = 0;
|
|
2613
2620
|
}
|
|
2614
|
-
|
|
2621
|
+
if (kanjiFormExamples.length > 0 && kanjiFormExamples.some(
|
|
2615
2622
|
(ex) => ex.includesTranslation === true
|
|
2616
|
-
)
|
|
2617
|
-
if (kanjiFormExamples.length > 0 && readingMatchingKanjiForms.size > 0)
|
|
2623
|
+
))
|
|
2618
2624
|
kanjiFormExamples = kanjiFormExamples.filter(
|
|
2619
|
-
(ex) =>
|
|
2620
|
-
(part) =>
|
|
2621
|
-
)
|
|
2625
|
+
(ex) => ex.includesTranslation === true || ex.ex.parts.some(
|
|
2626
|
+
(part) => ex.form === part.baseForm && part.glossNumber !== void 0
|
|
2627
|
+
)
|
|
2622
2628
|
);
|
|
2623
2629
|
if (readingExamples.length > 0 && readingExamples.some(
|
|
2624
2630
|
(ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
|
|
@@ -2628,9 +2634,7 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2628
2634
|
);
|
|
2629
2635
|
let wordExamples = [
|
|
2630
2636
|
...word.kanjiForms !== void 0 ? [...readingMatchingKanjiFormExamples, ...kanjiFormExamples] : readingExamples
|
|
2631
|
-
]
|
|
2632
|
-
(a, b) => a.ex.phrase.length - b.ex.phrase.length
|
|
2633
|
-
);
|
|
2637
|
+
];
|
|
2634
2638
|
seenPhrases.clear();
|
|
2635
2639
|
const glossSpecificExamples = [];
|
|
2636
2640
|
for (let i = 0; i < word.translations.length; i++)
|
|
@@ -2663,12 +2667,14 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2663
2667
|
wordExamples = glossSpecificExamples;
|
|
2664
2668
|
}
|
|
2665
2669
|
if (wordExamples.length > 0) {
|
|
2666
|
-
word.phrases = (glossSpecificExamples.length === 0 ? wordExamples.slice(0, 5) : wordExamples).map(
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2670
|
+
word.phrases = (glossSpecificExamples.length === 0 ? wordExamples.slice(0, 5) : wordExamples).map(
|
|
2671
|
+
(ex) => ({
|
|
2672
|
+
phrase: ex.ex.furigana ?? ex.ex.phrase,
|
|
2673
|
+
translation: ex.ex.translation,
|
|
2674
|
+
originalPhrase: ex.ex.phrase,
|
|
2675
|
+
...ex.ex.glossNumber !== void 0 ? { glossNumber: ex.ex.glossNumber } : {}
|
|
2676
|
+
})
|
|
2677
|
+
);
|
|
2672
2678
|
word.tags.push("word::has_phrases");
|
|
2673
2679
|
if (glossSpecificExamples.length > 0)
|
|
2674
2680
|
word.tags.push("word::has_meaning-specific_phrases");
|