Files
epg/scripts/core/parser.js

31 lines
731 B
JavaScript
Raw Normal View History

2022-01-06 12:59:37 +03:00
const logger = require('./logger')
const file = require('./file')
const grabber = require('epg-grabber')
const parser = {}
2022-03-04 00:39:00 +03:00
parser.parseChannels = async function (filepath) {
2022-01-06 12:59:37 +03:00
const content = await file.read(filepath)
2022-03-04 00:39:00 +03:00
return grabber.parseChannels(content)
2022-01-06 12:59:37 +03:00
}
parser.parseLogs = async function (filepath) {
const content = await file.read(filepath)
if (!content) return []
const lines = content.split('\n')
return lines.map(line => (line ? JSON.parse(line) : null)).filter(l => l)
}
parser.parseNumber = function (string) {
const parsed = parseInt(string)
if (isNaN(parsed)) {
throw new Error('scripts/core/parser.js:parseNumber() Input value is not a number')
}
return parsed
}
module.exports = parser