Skip to content

Commit

Permalink
feat: implement text functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rgildiaz committed May 31, 2024
1 parent 16b78ef commit 868172c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const LETTER_VARIATIONS = {
a: "aAÀÁÂÃÄÅàáâãäåĀāĂ㥹ǍǎȀȁȂȃẠạẢảấầẩẫậắằẳẴặɐ𝐀𝐚𝑎𝒂𝒜𝒶𝓪𝔞𝕒𝖆𝖺𝗮𝘢𝙖𝚊𝚶𝛂𝜊𝝰𝞐𝞪",
f: "fFƑƒ𝐅𝐟𝑓𝒇𝒻𝓕𝓯𝔣𝕗𝖋𝖥𝗳𝘧𝙛𝚏𝚽𝛣𝜝𝝝𝞥𝟊",
i: "iIÌÍÎÏìíîïĨĩĪīĬĭĮįİıǏǐȈȉȊȋỈỉịɨℹ𝐈𝐢𝑖𝒊𝓘𝓲𝔦𝕚𝖎𝗂𝗜𝗶𝘪𝙞𝚒𝛊𝜄𝝸𝞘𝟗",
r: "rRŔṘŘȐȒṚŖṞṜƦɌⱤŕṙřȑȓṛŗṟṝɍ℞®𝐑𝑟𝑹𝒓ℛ𝓇𝓡𝓻ℜ𝔯𝕽𝖗ℝ𝕣𝚪𝞒",
};

export function getRandomTitle() {
let title = "";
for (let i = 0; i < 1; i++) {
title += getRandomVariation('r')
}
return title;
}

export function getRandomVariation(characters: string[] | string) {
if (typeof characters === "string") {
characters = characters.split("");
}

let variations = [];
characters.forEach((char) => {
if (LETTER_VARIATIONS[char]) {
const letter = getRandomChar(LETTER_VARIATIONS[char]);
variations.push(letter);
} else {
variations.push(char);
}
});

return variations;
}

function getRandomChar(options: string) {
if (Math.random() < 0.01) {
return "";
}
return options[Math.floor(Math.random() * options.length)];
}

0 comments on commit 868172c

Please sign in to comment.