henkan 0.1.3 → 0.2.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.
- package/dist/index.cjs.js +87 -57
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +85 -57
- package/dist/index.mjs.map +3 -3
- package/dist/types/types.d.ts +24 -3
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/README.md +1 -0
- package/docs/api/functions/capitalizeString.md +1 -1
- package/docs/api/functions/convertJMdict.md +1 -1
- 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 +14 -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 +8 -8
- 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 +31 -21
- package/docs/api/interfaces/KanjiComponent.md +3 -3
- package/docs/api/interfaces/KanjiForm.md +3 -3
- package/docs/api/interfaces/NoteAndTag.md +31 -0
- 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 +7 -7
- 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 +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -1397,8 +1397,11 @@ function convertKanjiDic(xmlString) {
|
|
|
1397
1397
|
}
|
|
1398
1398
|
if (isValidArray(group.meaning)) {
|
|
1399
1399
|
for (const meaning of group.meaning)
|
|
1400
|
-
if (typeof meaning === "string")
|
|
1400
|
+
if (typeof meaning === "string") {
|
|
1401
|
+
if (kanjiObj.isKokuji === void 0 && meaning === "(kokuji)")
|
|
1402
|
+
kanjiObj.isKokuji = true;
|
|
1401
1403
|
groupObj.meanings.push(meaning);
|
|
1404
|
+
}
|
|
1402
1405
|
}
|
|
1403
1406
|
if (groupObj.readings.length > 0 || groupObj.meanings.length > 0)
|
|
1404
1407
|
rmObj.groups.push(groupObj);
|
|
@@ -1580,11 +1583,12 @@ function lookupWordNote(key, notes, tags, required, fallback) {
|
|
|
1580
1583
|
);
|
|
1581
1584
|
if (!info) {
|
|
1582
1585
|
if (required) throw new Error(`Invalid note info for ${key}`);
|
|
1583
|
-
notes.push(fallback != null ? fallback : key);
|
|
1584
|
-
return;
|
|
1586
|
+
if (notes) notes.push(fallback != null ? fallback : key);
|
|
1587
|
+
return { note: fallback != null ? fallback : key };
|
|
1585
1588
|
}
|
|
1586
|
-
tags.push(info[0]);
|
|
1587
|
-
notes.push(info[1]);
|
|
1589
|
+
if (tags) tags.push(`word::${info[0]}`);
|
|
1590
|
+
if (notes) notes.push(info[1]);
|
|
1591
|
+
return { note: info[1], tag: `word::${info[0]}` };
|
|
1588
1592
|
}
|
|
1589
1593
|
var wordAddNoteArray = (arr, cb) => {
|
|
1590
1594
|
if (!arr) return;
|
|
@@ -1601,40 +1605,50 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1601
1605
|
translations: [],
|
|
1602
1606
|
noteID: `word_${dictWord.id}`,
|
|
1603
1607
|
...noteTypeName ? { noteTypeName } : {},
|
|
1604
|
-
...deckPath ? { deckPath } : {}
|
|
1608
|
+
...deckPath ? { deckPath } : {},
|
|
1609
|
+
tags: []
|
|
1605
1610
|
};
|
|
1611
|
+
if (dictWord.isCommon === true) word.common = true;
|
|
1606
1612
|
if (dictWord.kanjiForms)
|
|
1607
1613
|
word.kanjiForms = dictWord.kanjiForms.map(
|
|
1608
|
-
(dictKanjiForm) => {
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1614
|
+
(dictKanjiForm) => ({
|
|
1615
|
+
kanjiForm: dictKanjiForm.form,
|
|
1616
|
+
...dictKanjiForm.notes ? {
|
|
1617
|
+
notes: dictKanjiForm.notes.map((note) => {
|
|
1618
|
+
var _a;
|
|
1619
|
+
const noteAndTag = lookupWordNote(
|
|
1620
|
+
note,
|
|
1621
|
+
void 0,
|
|
1622
|
+
word.tags,
|
|
1623
|
+
false,
|
|
1624
|
+
note
|
|
1625
|
+
);
|
|
1626
|
+
return capitalizeString((_a = noteAndTag.note) != null ? _a : note);
|
|
1627
|
+
})
|
|
1628
|
+
} : {}
|
|
1629
|
+
})
|
|
1620
1630
|
);
|
|
1621
|
-
word.readings = dictWord.readings.map((dictReading) => {
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1631
|
+
word.readings = dictWord.readings.map((dictReading) => ({
|
|
1632
|
+
reading: dictReading.reading,
|
|
1633
|
+
...dictReading.kanjiFormRestrictions || dictReading.notes ? {
|
|
1634
|
+
notes: [
|
|
1635
|
+
...dictReading.kanjiFormRestrictions ? dictReading.kanjiFormRestrictions.map(
|
|
1636
|
+
(restriction) => `Reading restricted to ${restriction}`
|
|
1637
|
+
) : [],
|
|
1638
|
+
...dictReading.notes ? dictReading.notes.map((note) => {
|
|
1639
|
+
var _a;
|
|
1640
|
+
const noteAndTag = lookupWordNote(
|
|
1641
|
+
note,
|
|
1642
|
+
void 0,
|
|
1643
|
+
word.tags,
|
|
1644
|
+
false,
|
|
1645
|
+
note
|
|
1646
|
+
);
|
|
1647
|
+
return capitalizeString((_a = noteAndTag.note) != null ? _a : note);
|
|
1648
|
+
}) : []
|
|
1649
|
+
]
|
|
1650
|
+
} : {}
|
|
1651
|
+
}));
|
|
1638
1652
|
let usuallyInKanaMeanings = 0;
|
|
1639
1653
|
word.translations = dictWord.meanings.map((dictMeaning) => {
|
|
1640
1654
|
if (!dictMeaning.translations)
|
|
@@ -1655,7 +1669,6 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1655
1669
|
}
|
|
1656
1670
|
);
|
|
1657
1671
|
const notes = [];
|
|
1658
|
-
word.tags = [];
|
|
1659
1672
|
wordAddNoteArray(
|
|
1660
1673
|
dictMeaning.kanjiFormRestrictions,
|
|
1661
1674
|
(restriction) => notes.push(`Meaning restricted to ${restriction}`)
|
|
@@ -1726,7 +1739,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1726
1739
|
}
|
|
1727
1740
|
if (word.kanji.length === 0) delete word.kanji;
|
|
1728
1741
|
}
|
|
1729
|
-
if (examples) {
|
|
1742
|
+
if (examples && dictWord.hasPhrases === true) {
|
|
1730
1743
|
const readings = new Set(
|
|
1731
1744
|
word.readings.filter(
|
|
1732
1745
|
(reading) => !reading.notes || reading.notes && !reading.notes.some(
|
|
@@ -1798,6 +1811,7 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1798
1811
|
}
|
|
1799
1812
|
}
|
|
1800
1813
|
function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
1814
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1801
1815
|
try {
|
|
1802
1816
|
const dictKanji = dict.find(
|
|
1803
1817
|
(entry) => entry.kanji === kanjiChar
|
|
@@ -1912,26 +1926,28 @@ function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
|
1912
1926
|
let codePoint = kanji.kanji.codePointAt(0);
|
|
1913
1927
|
if (codePoint !== void 0) {
|
|
1914
1928
|
codePoint = codePoint.toString(16);
|
|
1929
|
+
const fileNames = [
|
|
1930
|
+
`0${codePoint}.svg`,
|
|
1931
|
+
`${codePoint}.svg`
|
|
1932
|
+
];
|
|
1915
1933
|
const svg = svgList.find(
|
|
1916
|
-
(svgFile) =>
|
|
1934
|
+
(svgFile) => fileNames.includes(svgFile.toLowerCase())
|
|
1917
1935
|
);
|
|
1918
1936
|
if (svg) kanji.svg = svg;
|
|
1919
1937
|
}
|
|
1920
1938
|
}
|
|
1921
1939
|
kanji.tags = [];
|
|
1922
|
-
if (
|
|
1923
|
-
kanji.
|
|
1924
|
-
kanji.
|
|
1925
|
-
(meaning) => meaning !== "(kokuji)"
|
|
1926
|
-
);
|
|
1940
|
+
if (dictKanji.isKokuji === true) {
|
|
1941
|
+
kanji.kokuji = true;
|
|
1942
|
+
kanji.tags.push("kanji::kokuji");
|
|
1927
1943
|
}
|
|
1928
1944
|
kanji.tags.push(
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
...kanji.
|
|
1945
|
+
`kanji::onyomi::${(_b = (_a = kanji.onyomi) == null ? void 0 : _a.length) != null ? _b : 0}`,
|
|
1946
|
+
`kanji::kunyomi::${(_d = (_c = kanji.kunyomi) == null ? void 0 : _c.length) != null ? _d : 0}`,
|
|
1947
|
+
`kanji::nanori::${(_f = (_e = kanji.nanori) == null ? void 0 : _e.length) != null ? _f : 0}`,
|
|
1948
|
+
`kanji::strokes::${(_g = kanji.strokes) != null ? _g : "unknown"}`,
|
|
1949
|
+
`kanji::words::${(_i = (_h = kanji.words) == null ? void 0 : _h.length) != null ? _i : 0}`,
|
|
1950
|
+
...kanji.svg ? ["kanji::has_svg"] : []
|
|
1935
1951
|
);
|
|
1936
1952
|
return kanji;
|
|
1937
1953
|
} else throw new Error(`Kanji ${kanjiChar} not found`);
|
|
@@ -1940,6 +1956,7 @@ function getKanji(kanjiChar, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
|
1940
1956
|
}
|
|
1941
1957
|
}
|
|
1942
1958
|
function getKanjiExtended(kanjiChar, info, dict, useJpdbWords, jmDict, svgList, noteTypeName, deckPath) {
|
|
1959
|
+
var _a, _b, _c, _d;
|
|
1943
1960
|
try {
|
|
1944
1961
|
const kanji = getKanji(
|
|
1945
1962
|
kanjiChar,
|
|
@@ -1955,12 +1972,25 @@ function getKanjiExtended(kanjiChar, info, dict, useJpdbWords, jmDict, svgList,
|
|
|
1955
1972
|
kanji.mnemonic = info.mnemonic;
|
|
1956
1973
|
if (useJpdbWords === true && info.words && info.words.length > 0)
|
|
1957
1974
|
kanji.words = info.words;
|
|
1958
|
-
if (kanji.
|
|
1959
|
-
kanji.tags.push(
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1975
|
+
if (kanji.tags) {
|
|
1976
|
+
kanji.tags.push(`kanji::components::${(_b = (_a = kanji.components) == null ? void 0 : _a.length) != null ? _b : 0}`);
|
|
1977
|
+
if (kanji.mnemonic && kanji.mnemonic.length > 0)
|
|
1978
|
+
kanji.tags.push("kanji::has_mnemonic");
|
|
1979
|
+
if (useJpdbWords === true && kanji.words) {
|
|
1980
|
+
if (!kanji.tags.some((tag, index) => {
|
|
1981
|
+
var _a2, _b2;
|
|
1982
|
+
if (tag.startsWith("kanji::words::")) {
|
|
1983
|
+
kanji.tags.splice(
|
|
1984
|
+
index,
|
|
1985
|
+
1,
|
|
1986
|
+
`kanji::words::${(_b2 = (_a2 = kanji.words) == null ? void 0 : _a2.length) != null ? _b2 : 0}`
|
|
1987
|
+
);
|
|
1988
|
+
return true;
|
|
1989
|
+
} else return false;
|
|
1990
|
+
}))
|
|
1991
|
+
kanji.tags.push(`kanji::words::${(_d = (_c = kanji.words) == null ? void 0 : _c.length) != null ? _d : 0}`);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1964
1994
|
if (kanji.fromJpdb === true && (kanji.mnemonic || kanji.components && kanji.components.length > 0 || kanji.words))
|
|
1965
1995
|
kanji.source = `https://jpdb.io/kanji/${kanji.kanji}#a`;
|
|
1966
1996
|
return kanji;
|
|
@@ -2165,12 +2195,12 @@ function generateAnkiNote(entry) {
|
|
|
2165
2195
|
(onyomiEntry) => createEntry(
|
|
2166
2196
|
`<span class="kanji kanji-onyomi">${onyomiEntry}</span>`
|
|
2167
2197
|
)
|
|
2168
|
-
).join("") :
|
|
2198
|
+
).join("") : `<span class="kanji kanji-onyomi">(no onyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span`,
|
|
2169
2199
|
entry.kunyomi ? entry.kunyomi.map(
|
|
2170
2200
|
(kunyomiEntry) => createEntry(
|
|
2171
2201
|
`<span class="kanji kanji-kunyomi">${kunyomiEntry}</span>`
|
|
2172
2202
|
)
|
|
2173
|
-
).join("") :
|
|
2203
|
+
).join("") : `<span class="kanji kanji-kunyomi">(no kunyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
|
|
2174
2204
|
entry.nanori ? entry.nanori.map(
|
|
2175
2205
|
(nanoriEntry) => createEntry(
|
|
2176
2206
|
`<span class="kanji kanji-nanori">${nanoriEntry}</span>`
|