iptv-database/scripts/core/idCreator.ts
2023-10-08 02:13:58 +03:00

17 lines
388 B
TypeScript

export class IDCreator {
create(name: string, country: string): string {
const slug = normalize(name)
const code = country.toLowerCase()
return `${slug}.${code}`
}
}
function normalize(name: string) {
return name
.replace(/^@/gi, 'At')
.replace(/^&/i, 'And')
.replace(/\+/gi, 'Plus')
.replace(/\s-(\d)/gi, ' Minus$1')
.replace(/[^a-z\d]+/gi, '')
}