mirror of
https://github.com/iptv-org/database.git
synced 2025-05-09 11:10:01 -04:00
25 lines
574 B
TypeScript
25 lines
574 B
TypeScript
export function createChannelId(
|
|
name: string | undefined,
|
|
country: string | undefined
|
|
): string | undefined {
|
|
if (!name || !country) return undefined
|
|
|
|
const slug = normalize(name)
|
|
const code = country.toLowerCase()
|
|
|
|
return `${slug}.${code}`
|
|
}
|
|
|
|
export function createFeedId(name: string) {
|
|
return normalize(name)
|
|
}
|
|
|
|
function normalize(string: string) {
|
|
return string
|
|
.replace(/^@/gi, 'At')
|
|
.replace(/^&/i, 'And')
|
|
.replace(/\+/gi, 'Plus')
|
|
.replace(/\s-(\d)/gi, ' Minus$1')
|
|
.replace(/^-(\d)/gi, 'Minus$1')
|
|
.replace(/[^a-z\d]+/gi, '')
|
|
}
|