UNPKG

stream-chat-react

Version:

React components to create chat conversations or livestream style chat

22 lines (21 loc) 739 B
export function escapeRegExp(text) { return text.replace(/[-[\]{}()*+?.,/\\^$|#]/g, '\\$&'); } export const detectHttp = /(http(s?):\/\/)?(www\.)?/; export const messageCodeBlocks = (message) => { const codeRegex = /```[a-z]*\n[\s\S]*?\n```|`[a-z]*[\s\S]*?`/gm; const matches = message.match(codeRegex); return matches || []; }; export const matchMarkdownLinks = (message) => { const regexMdLinks = /\[([^[]+)\](\(.*\))/gm; const matches = message.match(regexMdLinks); const singleMatch = /\[([^[]+)\]\((.*)\)/; const links = matches ? matches.map((match) => { const i = singleMatch.exec(match); return i && [i[1], i[2]]; }) : []; return links.flat(); };