From be3ad2ab589dd8ef030be67d7a992e900cf4caab Mon Sep 17 00:00:00 2001 From: 00Fjongl <65314359+00Fjongl@users.noreply.github.com> Date: Sun, 7 Jul 2024 01:48:14 -0500 Subject: [PATCH] Updated some functions to ES6 syntax and implemented the alternative to RegEx string replacement. --- src/randomization.mjs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/randomization.mjs b/src/randomization.mjs index ab7019c7..d37975a7 100644 --- a/src/randomization.mjs +++ b/src/randomization.mjs @@ -25,6 +25,43 @@ const insertText = (lis, str, newText) => { return str; }; +const randomListItem = lis => lis[Math.random() * lis.length | 0]; + +const charset = ["­", "​", "­"]; +const insertCharset = str => insertText( + charset, + str, + () => randomListItem(charRandom) +); + +const hutaoInsert = str => insertText( + "", + str, + () => randomListItem(splashRandom) +); + +const insertCooking = str => insertText( + "", + str, + () => `${randomListItem(cookingInserts)}` +); + +const cacheBusting = str => { + for (let item of Object.entries(cacheBustList)) + str = insertText(item[0], str, item[1]); + return str; +}; + +export const paintSource = str => insertCharset(hutaoInsert(insertCooking(cacheBusting(str)))); + +export const tryReadFile = file => existsSync(file) ? readFileSync(file, "utf8") : text404; + +/* +// All of this is now old code. +// The newer versions of these functions are directly above. +*/ +/* + function randomListItem(lis) { return lis[Math.floor(Math.random() * lis.length)]; } @@ -54,4 +91,6 @@ export function paintSource(str) { export function tryReadFile(file) { return existsSync(file) ? readFileSync(file, 'utf8') : text404; -} \ No newline at end of file +} + +*/ \ No newline at end of file