iptv-database/scripts/core/idCreator.ts

18 lines
388 B
TypeScript
Raw Permalink Normal View History

2023-10-07 19:13:58 -04:00
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, '')
}