This commit is contained in:
2026-09-15 22:57:34 +09:00
parent afa8f1fcb6
commit a9586d7dab
13 changed files with 897 additions and 123 deletions
+24
View File
@@ -14,3 +14,27 @@ export function sample<T>(arr: T[], n: number = arr.length): T[] {
/** sleep for N milliseconds */
export const sleep = (msec: number) =>
new Promise((resolve) => setTimeout(resolve, msec));
/** normalize user-visible text and neutralize accidental mentions/tags */
export const sanitizeText = (text: string) =>
text
.replaceAll(/\r\n?/g, "\n")
.replaceAll(/\n[\t ]+/g, "\n")
.replaceAll(/\n{3,}/g, "\n\n")
.trim()
.replaceAll("@", "")
.replaceAll("#", "");
const POLITE_ENDING =
/(?:||||||)(?:||)?$/u;
export function isPoliteEnough(text: string) {
const sentences = text
.split(/[]+/u)
.map((sentence) => sentence.trim())
.filter(Boolean);
return (
sentences.length > 0 &&
sentences.some((sentence) => POLITE_ENDING.test(sentence))
);
}