mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
option not to parse remarks
This commit is contained in:
parent
17aeacf594
commit
31973431ff
9 changed files with 25 additions and 14 deletions
|
@ -27,7 +27,8 @@ With `opt`, you can override the default options, which look like this:
|
||||||
when: new Date(),
|
when: new Date(),
|
||||||
direction: null, // only show departures heading to this station
|
direction: null, // only show departures heading to this station
|
||||||
duration: 10, // show departures for the next n minutes
|
duration: 10, // show departures for the next n minutes
|
||||||
stationLines: false // parse & expose lines of the station?
|
stationLines: false, // parse & expose lines of the station?
|
||||||
|
remarks: true // parse & expose hints & warnings?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ With `opt`, you can override the default options, which look like this:
|
||||||
{
|
{
|
||||||
when: new Date(),
|
when: new Date(),
|
||||||
stopovers: true, // return stations on the way?
|
stopovers: true, // return stations on the way?
|
||||||
polyline: false // return a shape for the leg?
|
polyline: false, // return a shape for the leg?
|
||||||
|
remarks: true // parse & expose hints & warnings?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ With `opt`, you can override the default options, which look like this:
|
||||||
},
|
},
|
||||||
tickets: false, // return tickets? only available with some profiles
|
tickets: false, // return tickets? only available with some profiles
|
||||||
polylines: false, // return a shape for each leg?
|
polylines: false, // return a shape for each leg?
|
||||||
|
remarks: true, // parse & expose hints & warnings?
|
||||||
// Consider walking to nearby stations at the beginning of a journey?
|
// Consider walking to nearby stations at the beginning of a journey?
|
||||||
startWithWalking: true
|
startWithWalking: true
|
||||||
}
|
}
|
||||||
|
|
7
index.js
7
index.js
|
@ -34,7 +34,8 @@ const createClient = (profile, request = _request) => {
|
||||||
opt = Object.assign({
|
opt = Object.assign({
|
||||||
direction: null, // only show departures heading to this station
|
direction: null, // only show departures heading to this station
|
||||||
duration: 10, // show departures for the next n minutes
|
duration: 10, // show departures for the next n minutes
|
||||||
stationLines: false // parse & expose lines of the station?
|
stationLines: false, // parse & expose lines of the station?
|
||||||
|
remarks: true // parse & expose hints & warnings?
|
||||||
}, opt)
|
}, opt)
|
||||||
opt.when = new Date(opt.when || Date.now())
|
opt.when = new Date(opt.when || Date.now())
|
||||||
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
||||||
|
@ -115,6 +116,7 @@ const createClient = (profile, request = _request) => {
|
||||||
bike: false, // only bike-friendly journeys
|
bike: false, // only bike-friendly journeys
|
||||||
tickets: false, // return tickets?
|
tickets: false, // return tickets?
|
||||||
polylines: false, // return leg shapes?
|
polylines: false, // return leg shapes?
|
||||||
|
remarks: true, // parse & expose hints & warnings?
|
||||||
// Consider walking to nearby stations at the beginning of a journey?
|
// Consider walking to nearby stations at the beginning of a journey?
|
||||||
startWithWalking: true
|
startWithWalking: true
|
||||||
}, opt)
|
}, opt)
|
||||||
|
@ -322,7 +324,8 @@ const createClient = (profile, request = _request) => {
|
||||||
}
|
}
|
||||||
opt = Object.assign({
|
opt = Object.assign({
|
||||||
stopovers: true, // return stations on the way?
|
stopovers: true, // return stations on the way?
|
||||||
polyline: false
|
polyline: false,
|
||||||
|
remarks: true // parse & expose hints & warnings?
|
||||||
}, opt)
|
}, opt)
|
||||||
opt.when = new Date(opt.when || Date.now())
|
opt.when = new Date(opt.when || Date.now())
|
||||||
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
||||||
|
|
|
@ -81,11 +81,12 @@ const request = (profile, opt, data) => {
|
||||||
const d = b.svcResL[0].res
|
const d = b.svcResL[0].res
|
||||||
const c = d.common || {}
|
const c = d.common || {}
|
||||||
|
|
||||||
if (Array.isArray(c.remL)) {
|
d.hints = []
|
||||||
|
if (opt.remarks && Array.isArray(c.remL)) {
|
||||||
d.hints = c.remL.map(hint => profile.parseHint(profile, hint))
|
d.hints = c.remL.map(hint => profile.parseHint(profile, hint))
|
||||||
}
|
}
|
||||||
d.warnings = []
|
d.warnings = []
|
||||||
if (Array.isArray(c.himL)) {
|
if (opt.remarks && Array.isArray(c.himL)) {
|
||||||
d.warnings = c.himL.map(w => profile.parseWarning(profile, w))
|
d.warnings = c.himL.map(w => profile.parseWarning(profile, w))
|
||||||
}
|
}
|
||||||
if (Array.isArray(c.opL)) {
|
if (Array.isArray(c.opL)) {
|
||||||
|
|
|
@ -19,11 +19,7 @@ const createParseArrOrDep = (profile, opt, data, prefix) => {
|
||||||
when: when.toISO(),
|
when: when.toISO(),
|
||||||
direction: profile.parseStationName(d.dirTxt),
|
direction: profile.parseStationName(d.dirTxt),
|
||||||
line: lines[parseInt(d.prodX)] || null,
|
line: lines[parseInt(d.prodX)] || null,
|
||||||
remarks: ([]
|
remarks: [],
|
||||||
.concat(d.remL || [], d.msgL || [])
|
|
||||||
.map(ref => findRemark(hints, warnings, ref))
|
|
||||||
.filter(rem => !!rem) // filter unparsable
|
|
||||||
),
|
|
||||||
// todo: res.trip from rawLine.prodCtx.num?
|
// todo: res.trip from rawLine.prodCtx.num?
|
||||||
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
||||||
}
|
}
|
||||||
|
@ -56,6 +52,13 @@ const createParseArrOrDep = (profile, opt, data, prefix) => {
|
||||||
res.formerScheduledWhen = when.toISO()
|
res.formerScheduledWhen = when.toISO()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opt.remarks) {
|
||||||
|
res.remarks = []
|
||||||
|
.concat(d.remL || [], d.msgL || [])
|
||||||
|
.map(ref => findRemark(hints, warnings, ref))
|
||||||
|
.filter(rem => !!rem) // filter unparsable
|
||||||
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,12 +95,13 @@ const createParseJourneyLeg = (profile, opt, data) => {
|
||||||
res.stopovers = stopL.map(parse)
|
res.stopovers = stopL.map(parse)
|
||||||
|
|
||||||
// todo: is there a `pt.jny.remL`?
|
// todo: is there a `pt.jny.remL`?
|
||||||
if (Array.isArray(pt.jny.msgL)) {
|
if (opt.remarks && Array.isArray(pt.jny.msgL)) {
|
||||||
for (let i = 0; i < stopL.length; i++) {
|
for (let i = 0; i < stopL.length; i++) {
|
||||||
Object.defineProperty(res.stopovers[i], locX, {
|
Object.defineProperty(res.stopovers[i], locX, {
|
||||||
value: stopL[i].locX
|
value: stopL[i].locX
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// todo: apply leg-wide remarks if `parseStopovers` is false
|
||||||
applyRemarks(res, hints, warnings, pt.jny.msgL)
|
applyRemarks(res, hints, warnings, pt.jny.msgL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ const createParseJourney = (profile, opt, data) => {
|
||||||
legs
|
legs
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(j.msgL)) {
|
if (opt.remarks && Array.isArray(j.msgL)) {
|
||||||
res.remarks = []
|
res.remarks = []
|
||||||
for (let ref of j.msgL) {
|
for (let ref of j.msgL) {
|
||||||
const remark = findRemark(hints, warnings, ref)
|
const remark = findRemark(hints, warnings, ref)
|
||||||
|
|
|
@ -59,7 +59,7 @@ const createParseStopover = (profile, opt, data, date) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(st.msgL)) {
|
if (opt.remarks && Array.isArray(st.msgL)) {
|
||||||
res.remarks = []
|
res.remarks = []
|
||||||
for (let ref of st.msgL) {
|
for (let ref of st.msgL) {
|
||||||
const remark = findRemark(hints, warnings, ref)
|
const remark = findRemark(hints, warnings, ref)
|
||||||
|
|
Loading…
Add table
Reference in a new issue