-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.js
49 lines (49 loc) · 1.53 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { translationSymbols } from "./translations.js";
const whitespaceCharactersList = [
" ",
String.fromCodePoint(160),
String.fromCodePoint(8201),
String.fromCodePoint(8194),
String.fromCodePoint(8195)
];
export const whitespaceCharactersRegex = new RegExp("[" + whitespaceCharactersList.join("") + "]", "g");
export const isLetter = (potentialLetter) => {
if ("abcdefghijklmnopqrstuvwxyz".includes(potentialLetter)) {
return true;
}
return false;
};
export const indiciesOf = (sourceString, searchString) => {
const indicies = [];
for (let index = 0; index < sourceString.length - searchString.length; index += 1) {
if (sourceString.slice(index, searchString.length + index) === searchString) {
indicies.push(index);
}
}
return indicies;
};
export const isPotentialLeet = (potentialLeetString) => {
for (const leetSymbol of translationSymbols) {
if (isLetter(leetSymbol)) {
continue;
}
if (potentialLeetString.includes(leetSymbol)) {
return true;
}
}
return false;
};
export const combineStringArrays = (stringArrays) => {
if (stringArrays.length <= 1) {
return stringArrays[0];
}
const array1 = stringArrays[0];
const array2 = stringArrays[1];
const newArray = [];
for (const value1 of array1) {
for (const value2 of array2) {
newArray.push(value1 + " " + value2);
}
}
return combineStringArrays([newArray, ...stringArrays.slice(2)]);
};