(value: unknown)
| 11 | // Same result as zod's `z.url({ protocol: /^https?$/, hostname: |
| 12 | // z.regexes.domain, normalize: true })` after prepending https:// to bare hosts |
| 13 | export const parseHttpUrl = (value: unknown): string | null => { |
| 14 | if (typeof value !== 'string') { |
| 15 | return null; |
| 16 | } |
| 17 | |
| 18 | const withProtocol = urlStartRegexMatch.test(value) |
| 19 | ? value |
| 20 | : `https://${value}`; |
| 21 | |
| 22 | try { |
| 23 | const url = new URL(withProtocol.trim()); |
| 24 | |
| 25 | if ( |
| 26 | !domainRegex.test(url.hostname) || |
| 27 | (url.protocol !== 'http:' && url.protocol !== 'https:') |
| 28 | ) { |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | return url.href; |
| 33 | } catch (_) { |
| 34 | return null; |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | export const getTagPageLink = (tag: string): string => |
| 39 | `${process.env.NEXT_PUBLIC_WEBAPP_URL}tags/${encodeURIComponent(tag)}`; |
no outgoing calls
no test coverage detected