From 73d083f418287287c1031e16a014456a239d651f Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 12 Nov 2017 00:36:13 +0100 Subject: [PATCH] parse: default to null --- parse/departure.js | 4 ++-- parse/journey.js | 7 +++---- parse/movement.js | 6 +++--- parse/stopover.js | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/parse/departure.js b/parse/departure.js index c01ea81d..d017973a 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -15,10 +15,10 @@ const createParseDeparture = (timezone, stations, lines, remarks) => { const when = parseDateTime(timezone, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS) const res = { ref: d.jid, - station: stations[parseInt(d.stbStop.locX)], // todo: default to null + station: stations[parseInt(d.stbStop.locX)] || null, when: when.format(), direction: d.dirTxt, - line: lines[parseInt(d.prodX)], // todo: default to null + line: lines[parseInt(d.prodX)] || null, remarks: d.remL ? d.remL.map(findRemark) : [], trip: +d.jid.split('|')[1] // todo: this seems brittle } diff --git a/parse/journey.js b/parse/journey.js index da56dcf1..343a4147 100644 --- a/parse/journey.js +++ b/parse/journey.js @@ -38,8 +38,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey const dep = parseDateTime(tz, j.date, pt.dep.dTimeR || pt.dep.dTimeS) const arr = parseDateTime(tz, j.date, pt.arr.aTimeR || pt.arr.aTimeS) const res = { - // todo: what about null? - origin: clone(stations[parseInt(pt.dep.locX)]), + origin: clone(stations[parseInt(pt.dep.locX)]) || null, destination: clone(stations[parseInt(pt.arr.locX)]), departure: dep.format(), arrival: arr.format() @@ -55,7 +54,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey res.mode = 'walking' } else if (pt.type === 'JNY') { res.id = pt.jny.jid - res.line = lines[parseInt(pt.jny.prodX)] // todo: default null + res.line = lines[parseInt(pt.jny.prodX)] || null res.direction = pt.jny.dirTxt // todo: parse this if (pt.dep.dPlatfS) res.departurePlatform = pt.dep.dPlatfS @@ -71,7 +70,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey if (pt.jny.freq && pt.jny.freq.jnyL) { const parseAlternative = (a) => ({ - line: lines[parseInt(a.prodX)], // todo: default null + line: lines[parseInt(a.prodX)] || null, when: parseDateTime(tz, j.date, a.stopL[0].dTimeS).format() // todo: realtime }) res.alternatives = pt.jny.freq.jnyL diff --git a/parse/movement.js b/parse/movement.js index 27ddce18..8c44038e 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -28,7 +28,7 @@ const createParseMovement = (tz, locations, lines, remarks) => { const res = { direction: m.dirTxt, - line: lines[m.prodX], // default to null + line: lines[m.prodX] || null, coordinates: m.pos ? { latitude: m.pos.y / 1000000, longitude: m.pos.x / 1000000 @@ -40,8 +40,8 @@ const createParseMovement = (tz, locations, lines, remarks) => { if (m.ani && Array.isArray(m.ani.mSec)) { for (let i = 0; i < m.ani.mSec.length; i++) { res.frames.push({ - origin: locations[m.ani.fLocX[i]], // todo: default to null - destination: locations[m.ani.tLocX[i]], // todo: default to null + origin: locations[m.ani.fLocX[i]] || null, + destination: locations[m.ani.tLocX[i]] || null, t: m.ani.mSec[i] }) } diff --git a/parse/stopover.js b/parse/stopover.js index 0dea85bf..ab49c27f 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -5,7 +5,7 @@ const parseDateTime = require('./date-time') const createParseStopover = (tz, stations, lines, remarks, connection) => { const parseStopover = (st) => { const res = { - station: stations[parseInt(st.locX)] // default to null + station: stations[parseInt(st.locX)] || null } if (st.aTimeR || st.aTimeS) { const arr = parseDateTime(tz, connection.date, st.aTimeR || st.aTimeS)