Skip to content

Commit 021aaab

Browse files
committed
Clarify variable names
1 parent 50cdd22 commit 021aaab

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

root/static/scripts/guess-case/modes.js

+54-54
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ const POSTPROCESS_FIXLIST = [
9595
];
9696
/* eslint-enable no-multi-spaces */
9797

98-
function replaceMatch(matches, is, regex, replacement) {
98+
function replaceMatch(matches, inputString, regex, replacement) {
9999
// get reference to first set of parentheses
100100
const a = matches[1] || '';
101101

102102
// get reference to last set of parentheses
103103
const b = matches[matches.length - 1] || '';
104104

105105
// compile replace string
106-
return is.replace(regex, [a, replacement, b].join(''));
106+
return inputString.replace(regex, [a, replacement, b].join(''));
107107
}
108108

109109
/*
@@ -112,26 +112,26 @@ function replaceMatch(matches, is, regex, replacement) {
112112
* @param is the input string
113113
* @param fixes the list of fix objects to apply
114114
*/
115-
function runFixes(is, fixes) {
115+
function runFixes(inputString, fixes) {
116116
fixes.forEach(function (fix) {
117117
const [regex, replacement] = fix;
118118
let matches;
119119

120120
if (regex.global) {
121-
let oldis;
122-
while ((matches = regex.exec(is))) {
123-
oldis = is;
124-
is = replaceMatch(matches, is, regex, replacement);
125-
if (oldis === is) {
121+
let oldInputString;
122+
while ((matches = regex.exec(inputString))) {
123+
oldInputString = inputString;
124+
inputString = replaceMatch(matches, inputString, regex, replacement);
125+
if (oldInputString === inputString) {
126126
break;
127127
}
128128
}
129-
} else if ((matches = is.match(regex)) !== null) {
130-
is = replaceMatch(matches, is, regex, replacement);
129+
} else if ((matches = inputString.match(regex)) !== null) {
130+
inputString = replaceMatch(matches, inputString, regex, replacement);
131131
}
132132
});
133133

134-
return is;
134+
return inputString;
135135
}
136136

137137
const DefaultMode = {
@@ -155,26 +155,26 @@ const DefaultMode = {
155155
* - Convert 12', 12'', 12", 12in, and 12inch to '12" ' (followed by space).
156156
* - Do not convert strings like 80's.
157157
*/
158-
fixVinylSizes(is) {
159-
return is
158+
fixVinylSizes(inputString) {
159+
return inputString
160160
.replace(/(\s+|\()(7|10|12)(?:inch\b|in\b|'|''|")([^s]|$)/ig, '$1$2"$3')
161161
.replace(/((?:\s+|\()(?:7|10|12)")([^),\s])/, '$1 $2');
162162
},
163163

164-
isLowerCaseWord(w) {
165-
return LOWER_CASE_WORDS.test(w);
164+
isLowerCaseWord(word) {
165+
return LOWER_CASE_WORDS.test(word);
166166
},
167167

168-
isRomanNumber(w) {
169-
return getBooleanCookie('guesscase_roman') && ROMAN_NUMERALS.test(w);
168+
isRomanNumber(word) {
169+
return getBooleanCookie('guesscase_roman') && ROMAN_NUMERALS.test(word);
170170
},
171171

172172
isSentenceCaps() {
173173
return true;
174174
},
175175

176-
isUpperCaseWord(w) {
177-
return UPPER_CASE_WORDS.test(w);
176+
isUpperCaseWord(word) {
177+
return UPPER_CASE_WORDS.test(word);
178178
},
179179

180180
name: '',
@@ -188,23 +188,23 @@ const DefaultMode = {
188188
*/
189189
prepExtraTitleInfo(words) {
190190
const lastWord = words.length - 1;
191-
let wi = lastWord;
191+
let wordIndex = lastWord;
192192
let handlePreProcess = false;
193193

194-
while (wi >= 0 && (
194+
while (wordIndex >= 0 && (
195195
// skip whitespace
196-
(words[wi] === ' ') ||
196+
(words[wordIndex] === ' ') ||
197197

198198
// vinyl (7" or 12")
199-
(words[wi] === '"' &&
200-
(words[wi - 1] === '7' || words[wi - 1] === '12')) ||
201-
((words[wi + 1] || '') === '"' &&
202-
(words[wi] === '7' || words[wi] === '12')) ||
199+
(words[wordIndex] === '"' &&
200+
(words[wordIndex - 1] === '7' || words[wordIndex - 1] === '12')) ||
201+
((words[wordIndex + 1] || '') === '"' &&
202+
(words[wordIndex] === '7' || words[wordIndex] === '12')) ||
203203

204-
isPrepBracketWord(words[wi])
204+
isPrepBracketWord(words[wordIndex])
205205
)) {
206206
handlePreProcess = true;
207-
wi--;
207+
wordIndex--;
208208
}
209209

210210
/*
@@ -218,35 +218,35 @@ const DefaultMode = {
218218
* trackback the skipped spaces spaces, and then slurp the next word, so
219219
* see which word we found.
220220
*/
221-
if (wi < lastWord) {
221+
if (wordIndex < lastWord) {
222222
// the word at wi broke out of the loop above, is not extra title info
223-
wi++;
224-
while (words[wi] === ' ' && wi < lastWord) {
225-
wi++; // skip whitespace
223+
wordIndex++;
224+
while (words[wordIndex] === ' ' && wordIndex < lastWord) {
225+
wordIndex++; // skip whitespace
226226
}
227227

228228
/*
229229
* If we have a single word that needs to be put in parentheses, consult
230230
* the list of words were we don't do that, otherwise continue.
231231
*/
232232
const probe = words[lastWord];
233-
if (wi === lastWord && isPrepBracketSingleWord(probe)) {
233+
if (wordIndex === lastWord && isPrepBracketSingleWord(probe)) {
234234
handlePreProcess = false;
235235
}
236236

237-
if (handlePreProcess && wi > 0 && wi <= lastWord) {
238-
let newWords = words.slice(0, wi);
237+
if (handlePreProcess && wordIndex > 0 && wordIndex <= lastWord) {
238+
let newWords = words.slice(0, wordIndex);
239239

240-
if (newWords[wi - 1] === '(') {
240+
if (newWords[wordIndex - 1] === '(') {
241241
newWords.pop();
242242
}
243243

244-
if (newWords[wi - 1] === '-') {
244+
if (newWords[wordIndex - 1] === '-') {
245245
newWords.pop();
246246
}
247247

248248
newWords.push('(');
249-
newWords = newWords.concat(words.slice(wi, words.length));
249+
newWords = newWords.concat(words.slice(wordIndex, words.length));
250250
newWords.push(')');
251251
words = newWords;
252252
}
@@ -263,24 +263,24 @@ const DefaultMode = {
263263
*
264264
* keschte 2005-11-10 first version
265265
*/
266-
preProcessTitles(is) {
267-
return runFixes(is, PREPROCESS_FIXLIST);
266+
preProcessTitles(inputString) {
267+
return runFixes(inputString, PREPROCESS_FIXLIST);
268268
},
269269

270270
/*
271271
* Collect words from processed wordlist and apply minor fixes that
272272
* aren't handled in the specific function.
273273
*/
274-
runPostProcess(is) {
275-
return runFixes(is, POSTPROCESS_FIXLIST);
274+
runPostProcess(inputString) {
275+
return runFixes(inputString, POSTPROCESS_FIXLIST);
276276
},
277277

278-
toLowerCase(str) {
279-
return str.toLowerCase();
278+
toLowerCase(string) {
279+
return string.toLowerCase();
280280
},
281281

282-
toUpperCase(str) {
283-
return str.toUpperCase();
282+
toUpperCase(string) {
283+
return string.toUpperCase();
284284
},
285285
};
286286

@@ -302,22 +302,22 @@ export const English = {
302302

303303
name: 'English',
304304

305-
runPostProcess(is) {
306-
is = DefaultMode.runPostProcess(is);
305+
runPostProcess(inputString) {
306+
inputString = DefaultMode.runPostProcess(inputString);
307307
/*
308308
* This changes key names in titles to follow
309309
* the English classical music guidelines.
310310
* See https://musicbrainz.org/doc/Style/Classical/Language/English#Keys
311311
*/
312-
is = is.replace(
312+
inputString = inputString.replace(
313313
/\bin ([a-g])(?:[\s-]([Ff]lat|[Ss]harp))?\s(dorian|lydian|major|minor|mixolydian)(?:\b|$)/ig,
314314
function (match, p1, p2, p3) {
315315
return 'in ' + p1.toUpperCase() +
316316
(p2 ? '-' + p2.toLowerCase() : '') +
317317
' ' + p3.toLowerCase();
318318
},
319319
);
320-
return is;
320+
return inputString;
321321
},
322322
};
323323

@@ -335,8 +335,8 @@ export const French = {
335335

336336
name: 'French',
337337

338-
runPostProcess(is) {
339-
return DefaultMode.runPostProcess(is)
338+
runPostProcess(inputString) {
339+
return DefaultMode.runPostProcess(inputString)
340340
.replace(/([!\?;:]+)/gi, ' $1')
341341
.replace(/([«]+)/gi, '$1 ')
342342
.replace(/([»]+)/gi, ' $1')
@@ -374,8 +374,8 @@ export const Turkish = {
374374
},
375375
)),
376376

377-
isLowerCaseWord(w) {
378-
return LOWER_CASE_WORDS.test(w) || LOWER_CASE_WORDS_TURKISH.test(w);
377+
isLowerCaseWord(word) {
378+
return LOWER_CASE_WORDS.test(word) || LOWER_CASE_WORDS_TURKISH.test(word);
379379
},
380380

381381
isSentenceCaps() {

0 commit comments

Comments
 (0)