Skip to content

Commit 5882215

Browse files
committed
Convert indentation to tabs
1 parent 404cfd9 commit 5882215

File tree

1 file changed

+133
-133
lines changed

1 file changed

+133
-133
lines changed

main.js

Lines changed: 133 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -18,214 +18,214 @@ const specialWords = ["Chemistry", "Mathematics", "Geology", "Prosody", "Heraldr
1818

1919

2020
function run(input, parameters) {
21-
const wholeText = input[0];
22-
const word = getWord(wholeText);
23-
const definition = getDefinition(word, wholeText);
24-
const result = getResult(word, definition);
25-
return result;
21+
const wholeText = input[0];
22+
const word = getWord(wholeText);
23+
const definition = getDefinition(word, wholeText);
24+
const result = getResult(word, definition);
25+
return result;
2626
}
2727

2828

2929

3030
// --------------------------------------------------------------------------------------
3131
// Getting word. ------------------------------------------------------------------------
3232
const getWord = (text) => {
33-
text = text.replaceAll("·", "");
34-
text = text.split(" ")[0];
35-
text = removeWordException(text);
36-
return text;
33+
text = text.replaceAll("·", "");
34+
text = text.split(" ")[0];
35+
text = removeWordException(text);
36+
return text;
3737
}
3838

3939
const removeWordException = (word) => {
40-
word = removeHomonymNumberFromWord(word); // If word has multiple groups of definitions (like bat), remove 1 after word.
41-
word = removePartOfSpeechFromWord(word); // There are some words that part of seech follows right after word.
42-
return word;
40+
word = removeHomonymNumberFromWord(word); // If word has multiple groups of definitions (like bat), remove 1 after word.
41+
word = removePartOfSpeechFromWord(word); // There are some words that part of seech follows right after word.
42+
return word;
4343
}
4444

4545
const removeHomonymNumberFromWord = (word) => {
46-
if (word.charAt(word.length - 1) == "1" || word.charAt(word.length - 1) == "2") {
47-
word = word.substring(0, word.length - 1);
48-
}
49-
return word;
46+
if (word.charAt(word.length - 1) == "1" || word.charAt(word.length - 1) == "2") {
47+
word = word.substring(0, word.length - 1);
48+
}
49+
return word;
5050
}
5151

5252
const removePartOfSpeechFromWord = (word) => {
53-
partOfSpeech.forEach((element) => {
54-
word = word.replace(`${element}`, "");
55-
})
56-
return word;
53+
partOfSpeech.forEach((element) => {
54+
word = word.replace(`${element}`, "");
55+
})
56+
return word;
5757
}
5858

5959

6060
// -----------------------------------------------------------------------------------
6161
// Getting definition.----------------------------------------------------------------
6262
const getDefinition = (word, text) => {
63-
text = pruneText(text);
64-
text = formatText(text);
65-
if (hidingWordsFromDefinition === true) {
66-
text = hideWordsFromDefinition(word, text);
67-
}
68-
return text;
63+
text = pruneText(text);
64+
text = formatText(text);
65+
if (hidingWordsFromDefinition === true) {
66+
text = hideWordsFromDefinition(word, text);
67+
}
68+
return text;
6969
}
7070

7171
// pruning-------------------------------------------------------------------------------
7272
const pruneText = (text) => {
73-
text = removeAdditionalInformation(text);
74-
text = removeWordAndPronounciation(text);
75-
if (removingDotInformation === true) {
76-
text = removeDotInformation(text);
77-
}
78-
return text;
73+
text = removeAdditionalInformation(text);
74+
text = removeWordAndPronounciation(text);
75+
if (removingDotInformation === true) {
76+
text = removeDotInformation(text);
77+
}
78+
return text;
7979
}
8080

8181
const removeAdditionalInformation = (text) => {
82-
extraInformation.forEach((element) => {
83-
if (text.includes(`${element}`)) {
84-
text = text.substring(0, text.indexOf(`${element}`));
85-
}
86-
})
87-
return text;
82+
extraInformation.forEach((element) => {
83+
if (text.includes(`${element}`)) {
84+
text = text.substring(0, text.indexOf(`${element}`));
85+
}
86+
})
87+
return text;
8888
}
8989

9090
const removeWordAndPronounciation = (text) => {
91-
let indexs = [];
92-
partOfSpeech.forEach((element) => {
93-
if (text.includes(`${element}`)) {
94-
indexs.push(text.indexOf(`${element}`));
95-
}
96-
})
97-
let minIndex = Math.min(...indexs);
98-
if (text[minIndex - 1] === " ") {
99-
text = text.substring(minIndex - 1);
100-
} else {
101-
text = text.substring(minIndex);
102-
}
103-
return text;
91+
let indexs = [];
92+
partOfSpeech.forEach((element) => {
93+
if (text.includes(`${element}`)) {
94+
indexs.push(text.indexOf(`${element}`));
95+
}
96+
})
97+
let minIndex = Math.min(...indexs);
98+
if (text[minIndex - 1] === " ") {
99+
text = text.substring(minIndex - 1);
100+
} else {
101+
text = text.substring(minIndex);
102+
}
103+
return text;
104104
}
105105

106106
const removeDotInformation = (text) => {
107-
while (text.includes("•")) {
108-
const startIndex = text.indexOf("•") - 1;
109-
const endIndex = text.indexOf(". ", startIndex);
110-
text = text.substring(0, startIndex) + text.substring(endIndex + 1);
111-
}
112-
return text;
107+
while (text.includes("•")) {
108+
const startIndex = text.indexOf("•") - 1;
109+
const endIndex = text.indexOf(". ", startIndex);
110+
text = text.substring(0, startIndex) + text.substring(endIndex + 1);
111+
}
112+
return text;
113113
}
114114

115115

116116

117117
// formatting--------------------------------------------------------------------------
118118
const formatText = (text) => {
119-
text = formatByNumbers(text);
120-
text = formatByPartOfSpeech(text);
121-
text = breakLineProperly(text);
122-
if (htmlFormatting === true) {
123-
text = formatByHtml(text);
124-
}
125-
text = text.trim();
126-
return text;
119+
text = formatByNumbers(text);
120+
text = formatByPartOfSpeech(text);
121+
text = breakLineProperly(text);
122+
if (htmlFormatting === true) {
123+
text = formatByHtml(text);
124+
}
125+
text = text.trim();
126+
return text;
127127
}
128128

129129
const formatByNumbers = (text) => {
130-
for (i = 2; i < 10; i++) {
131-
text = text.replaceAll(` ${i} `, linebreak + `${i} `);
132-
}
133-
text = text.replaceAll(" •", linebreak + "• ");
134-
return text;
130+
for (i = 2; i < 10; i++) {
131+
text = text.replaceAll(` ${i} `, linebreak + `${i} `);
132+
}
133+
text = text.replaceAll(" •", linebreak + "• ");
134+
return text;
135135
}
136136

137137
const formatByPartOfSpeech = (text) => {
138-
partOfSpeech.forEach((element) => {
139-
text = text.replace(`${element} `, `${linebreak.repeat(2)}${element}${linebreak} `);
140-
let regexForPartOfSpeechesInsideParentheses = new RegExp(`(\\([a-z ]*?)\\<br\\>\\<br\\>(${element})\\<br\\>([a-z ]*?\\))`);
141-
text = text.replace(regexForPartOfSpeechesInsideParentheses, "$1 $2 $3"); // cancel line break part of speech inside defitition like "(as adecjtive pelleted)".
142-
})
143-
text = text.replace(`${linebreak}${linebreak}`, "");
144-
return text;
138+
partOfSpeech.forEach((element) => {
139+
text = text.replace(`${element} `, `${linebreak.repeat(2)}${element}${linebreak} `);
140+
let regexForPartOfSpeechesInsideParentheses = new RegExp(`(\\([a-z ]*?)\\<br\\>\\<br\\>(${element})\\<br\\>([a-z ]*?\\))`);
141+
text = text.replace(regexForPartOfSpeechesInsideParentheses, "$1 $2 $3"); // cancel line break part of speech inside defitition like "(as adecjtive pelleted)".
142+
})
143+
text = text.replace(`${linebreak}${linebreak}`, "");
144+
return text;
145145
}
146146

147147
const breakLineProperly = (text) => {
148-
partOfSpeech.forEach((element) => {
149-
let regexWithSquareBrackets = new RegExp(`(${element})\\<br\\>(\\(?[^\\<\\d]*?\\)?) ?(\\[.*?\\]) `, 'g');
150-
text = text.replace(regexWithSquareBrackets, `$1 $2 $3${linebreak}`);
151-
let regexWithoutSquareBrackets = new RegExp(`(${element})\\<br\\> *(\\([^\\<\\d]*?\\)) `);
152-
text = text.replace(regexWithoutSquareBrackets, `$1 $2${linebreak}`);
153-
})
154-
return text;
148+
partOfSpeech.forEach((element) => {
149+
let regexWithSquareBrackets = new RegExp(`(${element})\\<br\\>(\\(?[^\\<\\d]*?\\)?) ?(\\[.*?\\]) `, 'g');
150+
text = text.replace(regexWithSquareBrackets, `$1 $2 $3${linebreak}`);
151+
let regexWithoutSquareBrackets = new RegExp(`(${element})\\<br\\> *(\\([^\\<\\d]*?\\)) `);
152+
text = text.replace(regexWithoutSquareBrackets, `$1 $2${linebreak}`);
153+
})
154+
return text;
155155
}
156156

157157
const formatByHtml = (text) => {
158-
text = italicizeExampleSentences(text);
159-
text = italicizeSquareBracketWords(text);
160-
text = italicizeSpecialWords(text);
161-
text = changeItalicizedTextColorToDarkgrey(text);
162-
return text;
158+
text = italicizeExampleSentences(text);
159+
text = italicizeSquareBracketWords(text);
160+
text = italicizeSpecialWords(text);
161+
text = changeItalicizedTextColorToDarkgrey(text);
162+
return text;
163163
}
164164

165165

166166
const italicizeExampleSentences = (text) => {
167-
while (text.includes(": ")) {
168-
const indexOfColon = text.indexOf(": ");
169-
const indexOfPeriod = text.indexOf(".", indexOfColon);
170-
text = text.substring(0, indexOfPeriod + 1) + "</i>" + text.substring(indexOfPeriod + 1);
171-
text = text.replace(": ", ":<i> ");
172-
}
173-
return text;
167+
while (text.includes(": ")) {
168+
const indexOfColon = text.indexOf(": ");
169+
const indexOfPeriod = text.indexOf(".", indexOfColon);
170+
text = text.substring(0, indexOfPeriod + 1) + "</i>" + text.substring(indexOfPeriod + 1);
171+
text = text.replace(": ", ":<i> ");
172+
}
173+
return text;
174174
}
175175

176176
const italicizeSquareBracketWords = (text) => {
177-
text = text.replaceAll("[", "<i>[");
178-
text = text.replaceAll("]", "]</i>");
179-
return text;
177+
text = text.replaceAll("[", "<i>[");
178+
text = text.replaceAll("]", "]</i>");
179+
return text;
180180
}
181181

182182
const italicizeSpecialWords = (text) => {
183-
specialWords.forEach((element) => {
184-
text = text.replaceAll(`${element}`, `<i>${element}</i>`);
185-
})
186-
return text;
183+
specialWords.forEach((element) => {
184+
text = text.replaceAll(`${element}`, `<i>${element}</i>`);
185+
})
186+
return text;
187187
}
188188

189189
const changeItalicizedTextColorToDarkgrey = (text) => {
190-
text = text.replaceAll('<i>', `<span style="color:${exampleSentencesFontColor}"><i>`);
191-
text = text.replaceAll('</i>', '</i></span>');
192-
return text;
190+
text = text.replaceAll('<i>', `<span style="color:${exampleSentencesFontColor}"><i>`);
191+
text = text.replaceAll('</i>', '</i></span>');
192+
return text;
193193
}
194194

195195

196196

197197
// hiding -----------------------------------------------------------------------------
198198
const hideWordsFromDefinition = (word, text) => {
199-
const lastCharacterRemovedWord = word.substring(0, word.length - 1);
200-
const lastCharacter = word.substring(word.length - 1);
201-
202-
const startingVariations = [" ", "(", '“'];
203-
const wordForms = ["", "d", "ed", "s", "es", "ing", "er", "est", `${lastCharacter}ed`, `${lastCharacter}ing`];
204-
const wordFormsWithY = ["ing", "ied", "ies", "ier", "iest"];
205-
const endingVariations = [" ", ".", ",", ":", ";", ")", '”'];
206-
207-
startingVariations.forEach((startingVariation) => {
208-
wordForms.forEach((wordForm) => {
209-
endingVariations.forEach((endingVariation) => {
210-
text = text.replaceAll(`${startingVariation}${word}${wordForm}${endingVariation}`, `${startingVariation}${blank}${wordForm}${endingVariation}`);
211-
})
212-
})
213-
wordFormsWithY.forEach((wordFormWithY) => {
214-
endingVariations.forEach((endingVariation) => {
215-
text = text.replaceAll(`${startingVariation}${lastCharacterRemovedWord}${wordFormWithY}${endingVariation}`, `${startingVariation}${blank}${wordFormWithY}${endingVariation}`);
216-
})
217-
})
218-
})
219-
return text;
199+
const lastCharacterRemovedWord = word.substring(0, word.length - 1);
200+
const lastCharacter = word.substring(word.length - 1);
201+
202+
const startingVariations = [" ", "(", '“'];
203+
const wordForms = ["", "d", "ed", "s", "es", "ing", "er", "est", `${lastCharacter}ed`, `${lastCharacter}ing`];
204+
const wordFormsWithY = ["ing", "ied", "ies", "ier", "iest"];
205+
const endingVariations = [" ", ".", ",", ":", ";", ")", '”'];
206+
207+
startingVariations.forEach((startingVariation) => {
208+
wordForms.forEach((wordForm) => {
209+
endingVariations.forEach((endingVariation) => {
210+
text = text.replaceAll(`${startingVariation}${word}${wordForm}${endingVariation}`, `${startingVariation}${blank}${wordForm}${endingVariation}`);
211+
})
212+
})
213+
wordFormsWithY.forEach((wordFormWithY) => {
214+
endingVariations.forEach((endingVariation) => {
215+
text = text.replaceAll(`${startingVariation}${lastCharacterRemovedWord}${wordFormWithY}${endingVariation}`, `${startingVariation}${blank}${wordFormWithY}${endingVariation}`);
216+
})
217+
})
218+
})
219+
return text;
220220
}
221221

222222
// -------------------------------------------------------------------------------------------
223223
// Getting result-----------------------------------------------------------------------------
224224
const getResult = (word, definition) => {
225-
if (wordFirst === true) {
226-
result = `${word}${dividerBetweenWordAndDefinition}${definition}${endingCharacter}`;
227-
} else {
228-
result = `${definition}${dividerBetweenWordAndDefinition}${word}${endingCharacter}`;
229-
}
230-
return result;
225+
if (wordFirst === true) {
226+
result = `${word}${dividerBetweenWordAndDefinition}${definition}${endingCharacter}`;
227+
} else {
228+
result = `${definition}${dividerBetweenWordAndDefinition}${word}${endingCharacter}`;
229+
}
230+
return result;
231231
}

0 commit comments

Comments
 (0)