mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
'use strict'
|
|
|
|
// todo: move to separate file
|
|
const parseIcon = (i) => {
|
|
const res = {
|
|
type: i.res || null,
|
|
title: i.text || null
|
|
}
|
|
if (i.fg) res.fgColor = i.fg
|
|
if (i.bg) res.bgColor = i.bg
|
|
return res
|
|
}
|
|
|
|
const parseCommonData = (profile, opt, raw) => {
|
|
const res = Object.assign({}, raw)
|
|
const c = raw.common || {}
|
|
|
|
res.operators = []
|
|
if (Array.isArray(c.opL)) {
|
|
res.operators = c.opL.map(op => profile.parseOperator(profile, op))
|
|
}
|
|
|
|
res.icons = []
|
|
if (Array.isArray(c.icoL)) res.icons = c.icoL.map(parseIcon)
|
|
|
|
res.lines = []
|
|
if (Array.isArray(c.prodL)) {
|
|
const parse = profile.parseLine(profile, opt, res)
|
|
res.lines = c.prodL.map(parse)
|
|
}
|
|
|
|
res.locations = []
|
|
if (Array.isArray(c.locL)) {
|
|
const parse = loc => profile.parseLocation(profile, opt, res, loc)
|
|
res.locations = c.locL.map(parse)
|
|
|
|
for (let i = 0; i < res.locations.length; i++) {
|
|
const raw = c.locL[i]
|
|
const loc = res.locations[i]
|
|
if ('number' === typeof raw.mMastLocX) {
|
|
loc.station = Object.assign({}, res.locations[raw.mMastLocX])
|
|
loc.station.type = 'station'
|
|
} else if (raw.isMainMast) loc.type = 'station'
|
|
}
|
|
}
|
|
|
|
res.hints = []
|
|
if (opt.remarks && Array.isArray(c.remL)) {
|
|
res.hints = c.remL.map(hint => profile.parseHint(profile, hint, {...c, ...res}))
|
|
}
|
|
res.warnings = []
|
|
if (opt.remarks && Array.isArray(c.himL)) {
|
|
res.warnings = c.himL.map(w => profile.parseWarning(profile, w, {...c, ...res}))
|
|
}
|
|
|
|
res.polylines = []
|
|
if (opt.polylines && Array.isArray(c.polyL)) res.polylines = c.polyL
|
|
|
|
return res
|
|
}
|
|
|
|
module.exports = parseCommonData
|