-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuwujs.js
82 lines (78 loc) · 2.26 KB
/
uwujs.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// javascript implementation
class replacePair {
constructor(re, str) {
this.re = re;
this.str = str;
}
}
function isUpper(t) {
return t === t.toUpperCase();
}
function casePreserveReplace(str, a, b) {
return str
.replace(a.toLowerCase(), b.toLowerCase())
.replace(a.toUpperCase(), b.toUpperCase());
}
function thisCase(a, b) {
return isUpper(a) ? b.toUpperCase() : b.toLowerCase();
}
function uwufier(text) {
// console.log(`original text:\n${text}`);
const pairs = [
new replacePair(/you/gi, m => thisCase(m, "u")),
new replacePair(/thanks/gi, m => thisCase(m, "tnx")),
new replacePair(/like/gi, m => thisCase(m, "lik")),
new replacePair(/ok/gi, m => thisCase(m, "oki")),
new replacePair(/because/gi, m => thisCase(m, "cuz")),
new replacePair(/(?<![a-zA-Z])cry(?![a-zA-Z])/gi, m =>
thisCase(m, "cri " + randomChoice([";-;", "😭", ":c"]))
),
new replacePair(
/((?![aeiounwy])\w)([aeiou])(?!l)/gi,
m => m[0] + (Math.random() > 0.5 ? thisCase(m[0], "w") : "") + m[1]
),
new replacePair(/(?<=\w)[rl](?=\w)/gi, m => thisCase(m, "w")),
new replacePair(/is/gi, m =>
casePreserveReplace(
m,
"s",
thisCase(m, "z").repeat(Math.floor(1 + Math.random() * 3))
)
),
new replacePair(/a(nd)/gi, "$1"),
new replacePair(/w+/gi, m => thisCase(m, "w")),
new replacePair(/(h)(i)/gi, "$1$2$2$2$2"),
new replacePair(/([a-zA-Z?!~])\s+$/i, "$1$1$1"),
new replacePair(/\s+$/i, ""),
];
pairs.forEach(rp => {
text = text.replace(rp.re, rp.str);
});
const emojiPatch = "🥰😍😘😻💌💘💝💖💗💓💞💕💟❣️❤️🧡💛💚💙💜";
const emojis = [];
for (const ch of emojiPatch) {
emojis.push(ch);
}
function buildWholesome() {
let final = "";
for (
let i = 0;
i < Math.min(5, 1 + text.length / 5, Math.floor(Math.random() * 5));
i++
) {
final += randomChoice(emojis);
}
return final;
}
// console.log(`output:\n${text}`);
return (
text.replace(/([.?!~]\s+|$)/g, () => " " + buildWholesome() + " ") +
(Math.random() > 0.3
? randomChoice(["uwu", "owo", ":3", "xd", "c:", "^o^"])
: "")
);
}
function randomChoice(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
module.exports = uwufier;