2025-10-08 21:25:22 +03:00
|
|
|
import normalizeUrl from 'normalize-url'
|
|
|
|
|
|
|
|
|
|
export function isURI(string: string): boolean {
|
|
|
|
|
try {
|
2026-03-11 07:08:24 +03:00
|
|
|
const url = new URL(string)
|
|
|
|
|
return /^(http:|https:|mmsh:|rtsp:|rtmp:)/.test(url.protocol)
|
2025-10-08 21:25:22 +03:00
|
|
|
} catch {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function normalizeURL(url: string): string {
|
|
|
|
|
const normalized = normalizeUrl(url, { stripWWW: false })
|
|
|
|
|
|
|
|
|
|
return decodeURIComponent(normalized).replace(/\s/g, '+').toString()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function truncate(string: string, limit: number = 100) {
|
|
|
|
|
if (!string) return string
|
|
|
|
|
if (string.length < limit) return string
|
|
|
|
|
|
|
|
|
|
return string.slice(0, limit - 3) + '...'
|
|
|
|
|
}
|