iptv/scripts/core/id.js

20 lines
438 B
JavaScript
Raw Normal View History

2022-02-14 10:00:05 +01:00
const { transliterate } = require('transliteration')
2022-02-05 00:47:16 +01:00
2022-02-11 08:52:38 +01:00
const id = {}
2022-02-05 00:47:16 +01:00
2022-02-14 10:00:05 +01:00
id.generate = function (name, code) {
if (!name || !code) return null
2022-02-05 00:47:16 +01:00
2022-02-14 10:00:05 +01:00
name = name.replace(/ *\([^)]*\) */g, '')
name = name.replace(/ *\[[^)]*\] */g, '')
name = name.replace(/\+/gi, 'Plus')
name = name.replace(/[^a-z\d]+/gi, '')
name = name.trim()
name = transliterate(name)
code = code.toLowerCase()
2022-02-05 00:47:16 +01:00
2022-02-14 10:00:05 +01:00
return `${name}.${code}`
2022-02-05 00:47:16 +01:00
}
2022-02-11 08:52:38 +01:00
module.exports = id