{ "version": 3, "sources": ["../../../lib.shared.utils/find_urls.ts"], "sourcesContent": ["import {URL as NodeURL} from \"url\"\n// This is shared code, so we have do some tricks to make it work in Node and the browser.\nlet URL_: typeof NodeURL\nif (typeof NodeURL !== \"undefined\") {\n URL_ = NodeURL\n} else {\n URL_ = (global as any).URL\n}\n\nexport function find_urls(s: string): Array<[number, number]> {\n const result: Array<[number, number]> = []\n let i = 0\n for (;;) {\n const m = /http(s)?:\\/\\/[^\\s<]+/.exec(s)\n if (!m) {\n break\n }\n const j = m.index\n let candidate = m[0]\n let n = candidate.length\n while (n && !is_valid_URL(candidate)) {\n candidate = candidate.substr(0, --n)\n }\n if (n) {\n // Ignore last character if it is probably punctuation ...\n if (/[.?,]/.test(candidate.charAt(n - 1))) {\n candidate = candidate.substr(0, --n)\n }\n // Special handling for \")\" character: Truncate URL at first \")\" character\n // for which there is no preceding \"(\" character in `candidate` ...\n let open_parentheses = 0\n for (let k = 0; k < n; ++k) {\n const c = candidate.charAt(k)\n if (c === \"(\") {\n ++open_parentheses\n } else if (c === \")\") {\n if (!open_parentheses) {\n n = k\n } else {\n --open_parentheses\n }\n }\n }\n result.push([i + j, n])\n } else {\n // Skip bad candidate ...\n n = 1\n }\n s = s.substr(j + n)\n i += j + n\n }\n return result\n}\n\nfunction is_valid_URL(s: string) {\n try {\n return decodeURIComponent(new URL_(s).hostname).length > 1\n } catch {\n return false\n }\n}\n"], "mappings": "wCAEA,IAAIA,EACA,OAAO,OAAY,IACnBA,EAAO,OAEPA,EAAQ,OAAe,IAGpB,SAASC,EAAUC,EAAoC,CAC1D,IAAMC,EAAkC,CAAC,EACrCC,EAAI,EACR,OAAS,CACL,IAAMC,EAAI,uBAAuB,KAAKH,CAAC,EACvC,GAAI,CAACG,EACD,MAEJ,IAAMC,EAAID,EAAE,MACRE,EAAYF,EAAE,CAAC,EACfG,EAAID,EAAU,OAClB,KAAOC,GAAK,CAACC,EAAaF,CAAS,GAC/BA,EAAYA,EAAU,OAAO,EAAG,EAAEC,CAAC,EAEvC,GAAIA,EAAG,CAEC,QAAQ,KAAKD,EAAU,OAAOC,EAAI,CAAC,CAAC,IACpCD,EAAYA,EAAU,OAAO,EAAG,EAAEC,CAAC,GAIvC,IAAIE,EAAmB,EACvB,QAASC,EAAI,EAAGA,EAAIH,EAAG,EAAEG,EAAG,CACxB,IAAM,EAAIJ,EAAU,OAAOI,CAAC,EACxB,IAAM,IACN,EAAED,EACK,IAAM,MACRA,EAGD,EAAEA,EAFFF,EAAIG,EAKhB,CACAR,EAAO,KAAK,CAACC,EAAIE,EAAGE,CAAC,CAAC,CAC1B,MAEIA,EAAI,EAERN,EAAIA,EAAE,OAAOI,EAAIE,CAAC,EAClBJ,GAAKE,EAAIE,CACb,CACA,OAAOL,CACX,CA3CgBS,EAAAX,EAAA,aA6ChB,SAASQ,EAAaP,EAAW,CAC7B,GAAI,CACA,OAAO,mBAAmB,IAAIF,EAAKE,CAAC,EAAE,QAAQ,EAAE,OAAS,CAC7D,MAAQ,CACJ,MAAO,EACX,CACJ,CANSU,EAAAH,EAAA", "names": ["URL_", "find_urls", "s", "result", "i", "m", "j", "candidate", "n", "is_valid_URL", "open_parentheses", "k", "__name"] }