mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
Move to TanStack Start from Next.js (#184)
This commit is contained in:
25
web/app/lib/utils/url.ts
Normal file
25
web/app/lib/utils/url.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export function isValidUrl(string: string): boolean {
|
||||
try {
|
||||
new URL(string)
|
||||
return true
|
||||
} catch (_) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function isUrl(text: string): boolean {
|
||||
const pattern: RegExp =
|
||||
/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/
|
||||
return pattern.test(text)
|
||||
}
|
||||
|
||||
export function ensureUrlProtocol(
|
||||
url: string,
|
||||
defaultProtocol: string = "https://",
|
||||
): string {
|
||||
if (url.match(/^[a-zA-Z]+:\/\//)) {
|
||||
return url
|
||||
}
|
||||
|
||||
return `${defaultProtocol}${url.startsWith("//") ? url.slice(2) : url}`
|
||||
}
|
||||
Reference in New Issue
Block a user