From fcc53b5d2a86d2d9ac5e7353f9f0b658eb439f22 Mon Sep 17 00:00:00 2001 From: Milan Date: Sun, 6 Jan 2019 15:59:00 +0100 Subject: [PATCH] journeys: return object with journeys, earlierRef, laterRef :boom: Previously, an array with additional attributes `earlierRef` and `laterRef` was returned. When JSON-stringified, the attributes were missing. --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index af4bab4c..0547b497 100644 --- a/index.js +++ b/index.js @@ -185,6 +185,7 @@ const createClient = (profile, userAgent, request = _request) => { // until we have enough. // todo: revert this change, see https://github.com/public-transport/hafas-client/issues/76#issuecomment-424448449 const journeys = [] + let earlierRef, laterRef const more = (when, journeysRef) => { const query = { outDate: profile.formatDate(profile, when), @@ -224,7 +225,7 @@ const createClient = (profile, userAgent, request = _request) => { polylines: opt.polylines && d.common.polyL || [] }) - if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB + if (!earlierRef) earlierRef = d.outCtxScrB let latestDep = -Infinity for (let j of d.outConL) { @@ -232,8 +233,12 @@ const createClient = (profile, userAgent, request = _request) => { journeys.push(j) if (journeys.length >= opt.results) { // collected enough - journeys.laterRef = d.outCtxScrF - return journeys + laterRef = d.outCtxScrF + return { + earlierRef, + laterRef, + journeys + } } const dep = +new Date(j.legs[0].departure) if (dep > latestDep) latestDep = dep