13 lines
472 B
TypeScript
13 lines
472 B
TypeScript
import type { CmsNews } from './home-model'
|
|
|
|
export function safeWebUrl(value?: string | null): string | null {
|
|
if (!value?.trim()) return null
|
|
try {
|
|
const url = new URL(value)
|
|
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password ? url.href : null
|
|
} catch { return null }
|
|
}
|
|
export function visibleNews(items: CmsNews[]): CmsNews[] {
|
|
return items.filter(item => item.title?.trim() && Number.isFinite(Date.parse(item.date)))
|
|
}
|