Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
1.2 kB · 44 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445export function sanitizeWebsiteForDisplay(website: string): string { return website.replace(/^https?:\/\//i, '').replace(/\/$/, '')}
export function sanitizeWebsiteForLink(website: string): string { const normalized = website.toLowerCase() return !normalized.startsWith('javascript') ? normalized : `unsafe-${website}`}
export function isValidWebsiteFormat(website: string): boolean { const trimmedWebsite = website?.trim() || ''
if (!trimmedWebsite || trimmedWebsite.length === 0) { return true }
const normalizedWebsite = trimmedWebsite.toLowerCase()
if ('https://'.startsWith(normalizedWebsite)) { return true }
if (!normalizedWebsite.match(/^https:\/\/.+/)) { return false }
const domainMatch = normalizedWebsite.match(/^https:\/\/([^/\s]+)/) if (!domainMatch) { return false }
const domain = domainMatch[1]
// Check for valid domain structure: // - Must contain at least one dot // - Must have a valid TLD (at least 2 characters after the last dot) // - Cannot be just a single word without extension const domainPattern = /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/
return domainPattern.test(domain)}