From 8fd68427dad913910c192042e4c4bad0cd71308c Mon Sep 17 00:00:00 2001 From: MarvNC Date: Fri, 19 Jan 2024 16:41:36 -0800 Subject: [PATCH] Separate out logic --- src/util/convertEntryToYomitanTerm.js | 64 ++++++++++++++++++--------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/src/util/convertEntryToYomitanTerm.js b/src/util/convertEntryToYomitanTerm.js index d7a5727..223bac2 100644 --- a/src/util/convertEntryToYomitanTerm.js +++ b/src/util/convertEntryToYomitanTerm.js @@ -29,27 +29,13 @@ function convertLanguageDataToSC(languageData, isExplanation) { const languageLiScArray = []; for (const language in languageData) { - const languageInfo = languages[language]; - /** - * @type {string[]} - */ - const languageTexts = languageData[language]; - for (const languageText of languageTexts) { - languageLiScArray.push({ - tag: 'li', - lang: languageInfo.langCode, - style: { - listStyleType: `"(${ - isExplanation ? languageInfo.name : languageInfo.shortName - })"`, - }, - // TODO: use textParser function when built - content: languageText, - data: { - wordshk: languageInfo.langCode, - }, - }); - } + languageLiScArray.push( + ...convertLanguageEntryToLi( + language, + languageData[language], + isExplanation + ) + ); } /** @@ -65,3 +51,39 @@ function convertLanguageDataToSC(languageData, isExplanation) { return sc; } + +/** + * Converts a single language entry to a li item + * @param {string} language + * @param {string[]} languageTexts + * @param {boolean} isExplanation + * @returns {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent[]} + */ +function convertLanguageEntryToLi(language, languageTexts, isExplanation) { + /** + * @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent[]} + */ + const languageLiScArray = []; + const languageInfo = languages[language]; + /** + * @type {string[]} + */ + for (const languageText of languageTexts) { + languageLiScArray.push({ + tag: 'li', + lang: languageInfo.langCode, + style: { + listStyleType: `"(${ + isExplanation ? languageInfo.name : languageInfo.shortName + })"`, + }, + // TODO: use textParser function when built + content: languageText, + data: { + wordshk: languageInfo.langCode, + }, + }); + } + + return languageLiScArray; +}