2017-08-15 15:01:50 +02:00
|
|
|
/*
|
2024-09-09 15:57:16 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
Copyright 2017-2021 The Matrix.org Foundation C.I.C.
|
2017-08-15 15:01:50 +02:00
|
|
|
|
2024-09-09 15:57:16 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2017-08-15 15:01:50 +02:00
|
|
|
*/
|
|
|
|
|
2021-06-16 11:18:32 +02:00
|
|
|
const emailRegex = /^\S+@\S+\.\S+$/;
|
2017-09-27 16:30:58 +02:00
|
|
|
const mxUserIdRegex = /^@\S+:\S+$/;
|
|
|
|
const mxRoomIdRegex = /^!\S+:\S+$/;
|
2017-08-15 15:01:50 +02:00
|
|
|
|
2021-06-16 11:18:32 +02:00
|
|
|
export enum AddressType {
|
|
|
|
Email = "email",
|
|
|
|
MatrixUserId = "mx-user-id",
|
|
|
|
MatrixRoomId = "mx-room-id",
|
|
|
|
}
|
2017-08-15 15:01:50 +02:00
|
|
|
|
2021-06-16 11:18:32 +02:00
|
|
|
export function getAddressType(inputText: string): AddressType | null {
|
|
|
|
if (emailRegex.test(inputText)) {
|
|
|
|
return AddressType.Email;
|
|
|
|
} else if (mxUserIdRegex.test(inputText)) {
|
|
|
|
return AddressType.MatrixUserId;
|
|
|
|
} else if (mxRoomIdRegex.test(inputText)) {
|
|
|
|
return AddressType.MatrixRoomId;
|
2017-08-15 15:01:50 +02:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|