Discriminator in username

This commit is contained in:
Fedor Indutny
2022-10-18 10:12:02 -07:00
committed by GitHub
parent 58f0012f14
commit 00f82a6d39
54 changed files with 2706 additions and 892 deletions
+9 -19
View File
@@ -1,23 +1,13 @@
// Copyright 2021 Signal Messenger, LLC
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export const MAX_USERNAME = 26;
export const MIN_USERNAME = 4;
export type UsernameReservationType = Readonly<{
username: string;
previousUsername: string | undefined;
reservationToken: string;
}>;
export function isValidUsername(searchTerm: string): boolean {
return /^[a-z_][0-9a-z_]{3,25}$/.test(searchTerm);
}
export function getUsernameFromSearch(searchTerm: string): string | undefined {
if (/^[+0-9]+$/.test(searchTerm)) {
return undefined;
}
const match = /^@?(.*?)@?$/.exec(searchTerm);
if (match && match[1]) {
return match[1];
}
return undefined;
export enum ReserveUsernameError {
Unprocessable = 'Unprocessable',
Conflict = 'Conflict',
}