Initial commit

This commit is contained in:
2026-03-27 19:35:14 +01:00
commit 38581b88a4
68 changed files with 12137 additions and 0 deletions

36
lib/sanitize.ts Normal file
View File

@@ -0,0 +1,36 @@
export function sanitizePlainText(value: string) {
return value
.replace(/[\u0000-\u001F\u007F]/g, "")
.replace(/\s+/g, " ")
.trim();
}
export function sanitizeOptionalPlainText(value: string | null | undefined) {
if (!value) {
return undefined;
}
const sanitized = sanitizePlainText(value);
return sanitized.length > 0 ? sanitized : undefined;
}
export function normalizeUsername(value: string) {
return sanitizePlainText(value).toLowerCase().replace(/^@+/, "");
}
export function safeUrl(value: string | null | undefined) {
if (!value) {
return undefined;
}
const sanitized = value.trim();
try {
const url = new URL(sanitized);
if (!["http:", "https:"].includes(url.protocol)) {
return undefined;
}
return sanitized;
} catch {
return undefined;
}
}