Skip to content

Commit 3f58dcf

Browse files
committed
Implement validUrl helper
1 parent 55eecc0 commit 3f58dcf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/helpers/url_helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,11 @@ export function urlRoute(url: string): string {
128128
fragment: false,
129129
});
130130
}
131+
132+
export function validUrl(url: string): string | null {
133+
try {
134+
return new URL(url.trim()).toString();
135+
} catch (error) {
136+
return null;
137+
}
138+
}

0 commit comments

Comments
 (0)