1
0
Fork 0

make it ESM ready

This commit is contained in:
lesion 2023-01-23 12:42:25 +01:00
parent 1a78e2344c
commit baa181354f
3 changed files with 12 additions and 9 deletions

View file

@ -1,5 +1,5 @@
const ICAL = require('ical.js') import ICAL from 'ical.js'
const shows = require('./shows.js') import shows from './shows'
function max(a, b) { function max(a, b) {
if (a<b) return b if (a<b) return b
@ -204,7 +204,7 @@ async function get(manifest) {
} }
if (resp !== null) { if (resp !== null) {
try { try {
text = await resp.text() const text = await resp.text()
return parse(text) return parse(text)
} catch (e) { } catch (e) {
console.error('Error while parsing schedule', e) console.error('Error while parsing schedule', e)
@ -228,7 +228,7 @@ function parse(text) {
} }
module.exports = { export default {
get: get, get: get,
parse: parse, parse: parse,
RadioSchedule: RadioSchedule, RadioSchedule: RadioSchedule,

View file

@ -3,6 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"description": "", "description": "",
"main": "radiomanifest.js", "main": "radiomanifest.js",
"module": "radiomanifest.js",
"directories": { "directories": {
"test": "tests" "test": "tests"
}, },
@ -20,10 +21,10 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"jsdoc": "^3.6.10",
"docdash": "^1.2.0",
"chai": "^4.3.4", "chai": "^4.3.4",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"docdash": "^1.2.0",
"jsdoc": "^3.6.10",
"karma": "^6.3.9", "karma": "^6.3.9",
"karma-chrome-launcher": "^3.1.0", "karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^2.1.2", "karma-firefox-launcher": "^2.1.2",

View file

@ -2,6 +2,8 @@
* Represents a single show. This show could be defined in the shows.xml file, or could be inferred from the * Represents a single show. This show could be defined in the shows.xml file, or could be inferred from the
* schedule. * schedule.
*/ */
class RadioShow { class RadioShow {
constructor(name, description, website, feed, schedule, radio_calendar) { constructor(name, description, website, feed, schedule, radio_calendar) {
this.name = name this.name = name
@ -44,7 +46,7 @@ function parseRadioShows(xml) {
} }
let website = doc.evaluate('./info/metadata/show:website', bm, showsNamespaceResolver, XPathResult.STRING_TYPE).stringValue let website = doc.evaluate('./info/metadata/show:website', bm, showsNamespaceResolver, XPathResult.STRING_TYPE).stringValue
if (website === '') { if (website === '') {
website = getAttribute(bm, 'href', null) website = bm.getAttribute('href')
} }
const feed = doc.evaluate('./info/metadata/show:feed', bm, showsNamespaceResolver, XPathResult.STRING_TYPE).stringValue const feed = doc.evaluate('./info/metadata/show:feed', bm, showsNamespaceResolver, XPathResult.STRING_TYPE).stringValue
const schedule = doc.evaluate('./info/metadata/show:schedule', bm, showsNamespaceResolver, XPathResult.STRING_TYPE).stringValue const schedule = doc.evaluate('./info/metadata/show:schedule', bm, showsNamespaceResolver, XPathResult.STRING_TYPE).stringValue
@ -70,7 +72,7 @@ async function getShows(manifest) {
} }
if (resp !== null) { if (resp !== null) {
try { try {
text = await resp.text() const text = await resp.text()
const parser = new DOMParser() const parser = new DOMParser()
const showsDom = parser.parseFromString(text, 'text/xml') const showsDom = parser.parseFromString(text, 'text/xml')
return parseRadioShows(showsDom) return parseRadioShows(showsDom)
@ -90,7 +92,7 @@ function showsNamespaceResolver(prefix) {
} }
module.exports = { export default {
get: getShows, get: getShows,
parse: parseRadioShows, parse: parseRadioShows,
RadioShow: RadioShow, RadioShow: RadioShow,