| 1 | import { clsx, type ClassValue } from "clsx" |
| 2 | import { twMerge } from "tailwind-merge" |
| 3 | |
| 4 | export function cn(...inputs: ClassValue[]) { |
| 5 | return twMerge(clsx(inputs)) |
| 6 | } |
| 7 | |
| 8 | |
| 9 | export function isValidUrl(url:string):boolean { |
| 10 | try { |
| 11 | const urlObj = new URL(url) |
| 12 | return urlObj.protocol === "http:" || urlObj.protocol === "https:" |
| 13 | } catch (error) { |
| 14 | return false |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | export function ensureHttps(url:string):string { |
| 19 | if(!url.startsWith("https://") && !url.startsWith("https://")) { |
| 20 | return `https://${url}` |
| 21 | } |
| 22 | |
| 23 | if(url.startsWith("http://")) { |
| 24 | return url.replace("http://", "https://") |
| 25 | } |
| 26 | |
| 27 | return url |
| 28 | } |