import { Room } from '../types' ; import roomsCache from '../config/NodeCache' ; const PATH_REGEX = /^\/room\/(?<id>[A-Za-z0-9_-]+$)/ ; const ID_REGEX = /^(?<id>[A-Za-z0-9_-]+$)/ ; function getRoomFromLink ( link ) { let id ; try { const url = new URL ( link ) ; id = url . pathname . match ( PATH_REGEX ) ?. groups ?. id ; } catch ( error ) { id = link . match ( ID_REGEX ) ?. groups ?. id ; } return id !== undefined ? roomsCache . get ( id ) : undefined ; } export default getRoomFromLink ;