mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-11 14:28:10 +00:00
format codebase with prettier
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user