format codebase with prettier

This commit is contained in:
Evan
2025-01-30 19:46:36 -08:00
parent cd121a5cd4
commit 4ee37323f9
98 changed files with 12191 additions and 10234 deletions
+32 -28
View File
@@ -3,38 +3,42 @@ export const MAX_USERNAME_LENGTH = 20;
const validPattern = /^[a-zA-Z0-9_ ]+$/;
export function validateUsername(username: string): { isValid: boolean; error?: string } {
export function validateUsername(username: string): {
isValid: boolean;
error?: string;
} {
if (typeof username !== "string") {
return { isValid: false, error: "Username must be a string." };
}
if (typeof username !== 'string') {
return { isValid: false, error: "Username must be a string." };
}
if (username.length < MIN_USERNAME_LENGTH) {
return {
isValid: false,
error: `Username must be at least ${MIN_USERNAME_LENGTH} characters long.`,
};
}
if (username.length < MIN_USERNAME_LENGTH) {
return {
isValid: false,
error: `Username must be at least ${MIN_USERNAME_LENGTH} characters long.`,
};
}
if (username.length > MAX_USERNAME_LENGTH) {
return {
isValid: false,
error: `Username must not exceed ${MAX_USERNAME_LENGTH} characters.`,
};
}
if (username.length > MAX_USERNAME_LENGTH) {
return {
isValid: false,
error: `Username must not exceed ${MAX_USERNAME_LENGTH} characters.`,
};
}
if (!validPattern.test(username)) {
return {
isValid: false,
error: "Username can only contain letters, numbers, and underscores.",
};
}
if (!validPattern.test(username)) {
return {
isValid: false,
error: "Username can only contain letters, numbers, and underscores.",
};
}
// All checks passed
return { isValid: true };
// All checks passed
return { isValid: true };
}
export function sanitizeUsername(str: string): string {
const sanitized = str.replace(/[^a-zA-Z0-9]/g, '').slice(0, MAX_USERNAME_LENGTH);
return sanitized.padEnd(MIN_USERNAME_LENGTH, 'x')
};
const sanitized = str
.replace(/[^a-zA-Z0-9]/g, "")
.slice(0, MAX_USERNAME_LENGTH);
return sanitized.padEnd(MIN_USERNAME_LENGTH, "x");
}