mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-08 09:53:24 +00:00
555afe4abd
The regex was being recreated on every function call, causing unnecessary performance overhead. Hoist the RegExp to a module-level constant to reuse the compiled pattern.
20 lines
661 B
TypeScript
20 lines
661 B
TypeScript
export const roomIdPattern = '[a-z]{3}-[a-z]{4}-[a-z]{3}'
|
|
|
|
// Case-insensitive and with optional hyphens
|
|
export const flexibleRoomIdPattern =
|
|
'(?:[a-zA-Z0-9]{3}-?[a-zA-Z0-9]{4}-?[a-zA-Z0-9]{3})'
|
|
|
|
const roomRegex = new RegExp(`^${roomIdPattern}$`)
|
|
|
|
export const isRoomValid = (roomIdOrUrl: string) =>
|
|
roomRegex.test(roomIdOrUrl) ||
|
|
new RegExp(`^${window.location.origin}/${roomIdPattern}$`).test(roomIdOrUrl)
|
|
|
|
export const normalizeRoomId = (roomId: string) => {
|
|
const cleanId = roomId.toLowerCase().replace(/-/g, '')
|
|
if (cleanId.length === 10) {
|
|
return `${cleanId.slice(0, 3)}-${cleanId.slice(3, 7)}-${cleanId.slice(7, 10)}`
|
|
}
|
|
return roomId
|
|
}
|