MCPcopy Create free account
hub / github.com/dailydotdev/apps / parseHttpUrl

Function parseHttpUrl

packages/shared/src/lib/links.ts:13–36  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

11// Same result as zod's `z.url({ protocol: /^https?$/, hostname:
12// z.regexes.domain, normalize: true })` after prepending https:// to bare hosts
13export 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
38export const getTagPageLink = (tag: string): string =>
39 `${process.env.NEXT_PUBLIC_WEBAPP_URL}tags/${encodeURIComponent(tag)}`;

Callers 3

normalizeComposerUrlFunction · 0.90
parseCreativeFunction · 0.90
parseAdvertiserFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected