-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter-username.js
57 lines (56 loc) · 1.13 KB
/
filter-username.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
50
51
52
53
54
55
56
57
// Filters Discord usernames to replace or remove problematic characters.
function FilterUsername(username) {
const allowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_` ()[]!?\'*+/\\:=~#èáéíóúüñà';
const substitutions = {
'ғ': 'f',
'u': 'U',
'ᶜ': 'c',
'Ќ': 'K',
'ץ': 'Y',
'๏': 'o',
'Ữ': 'u',
'M': 'M',
'A': 'A',
'ŕ': 'r',
'K': 'K',
'𝘉': 'B',
'𝘶': 'u',
'𝘯': 'n',
'𝘪': 'i',
'𝘊': 'C',
'𝘩': 'h',
'𝘢': 'a',
'𝘰': 'o',
'𝘴': 's',
'♡': 'x',
'𝙋': 'P',
'𝘼': 'A',
'𝙄': 'I',
'乃': 'B',
'ㄥ': 'L',
'ㄩ': 'U',
'尺': 'R',
'î': 'i',
'ł': 'l',
'ø': 'o',
'Ł': 'L',
'$': 's',
};
for (const [before, after] of Object.entries(substitutions)) {
username = username.split(before).join(after);
}
let s = '';
for (let i = 0; i < username.length; i++) {
const c = username.charAt(i);
if (allowedChars.indexOf(c) >= 0) {
s += c;
}
}
const maxNameLength = 18;
s = s.trim().slice(0, maxNameLength).trim();
if (s.length === 0) {
s = 'John Doe';
}
return s;
}
module.exports = FilterUsername;