db-vendo-client/p/vbb/index.js

91 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-05-07 16:17:37 +02:00
// todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
2017-11-18 17:53:12 +01:00
2022-05-07 16:17:37 +02:00
import {parseHook} from '../../lib/profile-hooks.js'
2017-11-18 17:53:12 +01:00
2022-05-07 16:17:37 +02:00
import {parseAndAddLocationDHID} from './parse-loc-dhid.js'
import {parseLine as _parseLine} from '../../parse/line.js'
import {parseLocation as _parseLocation} from '../../parse/location.js'
import {parseJourney as _parseJourney} from '../../parse/journey.js'
import {parseDeparture as _parseDeparture} from '../../parse/departure.js'
2017-11-18 17:53:12 +01:00
const baseProfile = require('./base.json')
2022-05-07 16:17:37 +02:00
import {products} from './products.js'
2017-11-18 17:53:12 +01:00
2021-12-29 18:29:10 +01:00
const parseLineWithShortName = ({parsed}, p) => {
2019-10-20 00:19:52 +02:00
parsed.name = p.name.replace(/^(bus|tram)\s+/i, '')
return parsed
2017-11-18 17:53:12 +01:00
}
2019-10-20 00:19:52 +02:00
const parseLocation = ({parsed}, l) => {
2022-03-07 01:34:33 +01:00
parseAndAddLocationDHID(parsed, l)
2019-10-20 00:19:52 +02:00
return parsed
2017-11-18 17:53:12 +01:00
}
// todo: move this to parse/tickets.js?
2019-10-20 00:19:52 +02:00
const parseJourneyWithTickets = ({parsed}, j) => {
if (
j.trfRes &&
Array.isArray(j.trfRes.fareSetL)
2019-10-20 00:19:52 +02:00
) {
parsed.tickets = j.trfRes.fareSetL
.map((s) => {
if (!Array.isArray(s.fareL) || s.fareL.length === 0) return null
return {
name: s.name,
description: s.desc,
tickets: s.fareL.map((f) => ({
// todo: sometimes there's also t.ticketL
name: f.name,
price: f.price,
})),
}
})
.filter(set => !!set)
// todo: j.trfRes.totalPrice
// todo: j.trfRes.msgL
}
2019-10-20 00:19:52 +02:00
return parsed
}
2019-10-20 00:19:52 +02:00
const ringbahnClockwise = /^ringbahn s\s?41$/i
const ringbahnAnticlockwise = /^ringbahn s\s?42$/i
const parseDepartureRenameRingbahn = ({parsed}) => {
if (parsed.line && parsed.line.product === 'suburban') {
const d = parsed.direction && parsed.direction.trim()
if (ringbahnClockwise.test(d)) {
parsed.direction = 'Ringbahn S41 ⟳'
} else if (ringbahnAnticlockwise.test(d)) {
parsed.direction = 'Ringbahn S42 ⟲'
}
}
2019-10-20 00:19:52 +02:00
return parsed
}
2022-05-07 16:17:37 +02:00
const profile = {
...baseProfile,
locale: 'de-DE',
2017-11-18 17:53:12 +01:00
timezone: 'Europe/Berlin',
products: products,
2017-12-12 03:28:54 +01:00
2021-12-29 18:29:10 +01:00
parseLine: parseHook(_parseLine, parseLineWithShortName),
2019-10-20 00:19:52 +02:00
parseLocation: parseHook(_parseLocation, parseLocation),
parseJourney: parseHook(_parseJourney, parseJourneyWithTickets),
parseDeparture: parseHook(_parseDeparture, parseDepartureRenameRingbahn),
2017-11-18 17:53:12 +01:00
journeysWalkingSpeed: true,
refreshJourneyUseOutReconL: true,
trip: true,
2018-08-26 18:35:27 +02:00
radar: true,
2020-09-16 17:21:59 +02:00
reachableFrom: true,
2017-11-18 17:53:12 +01:00
}
2022-05-07 16:17:37 +02:00
export {
profile,
}