From 595c7458305e3c8494c5c7a5340b1511fc250558 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sat, 16 Dec 2017 03:20:11 +0100 Subject: [PATCH] VBB: support 7-digit stations --- p/vbb/index.js | 12 +++++++++--- test/vbb.js | 5 ++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/p/vbb/index.js b/p/vbb/index.js index fa632345..a1018930 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -128,10 +128,16 @@ const createParseDeparture = (profile, stations, lines, remarks) => { return parseDepartureRenameRingbahn } -const isIBNR = /^\d{9,}$/ +const validIBNR = /^\d+$/ const formatStation = (id) => { - if (!isIBNR.test(id)) throw new Error('station ID must be an IBNR.') - id = to9Digit(id) + if ('string' !== typeof id) throw new Error('station ID must be a string.') + const l = id.length + if ((l !== 7 && l !== 9 && l !== 12) || !validIBNR.test(id)) { + throw new Error('station ID must be a valid IBNR.') + } + // The VBB has some 7-digit stations. We don't convert them to 12 digits, + // because it only recognizes in the 7-digit format. see derhuerst/vbb-hafas#22 + if (l !== 7) id = to9Digit(id) return _formatStation(id) } diff --git a/test/vbb.js b/test/vbb.js index a96faedc..ccf03bb2 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -260,10 +260,9 @@ test('departures', co.wrap(function* (t) { t.end() })) -// todo -test.skip('departures at 7-digit station', co.wrap(function* (t) { +test('departures at 7-digit station', co.wrap(function* (t) { const eisenach = '8010097' // see derhuerst/vbb-hafas#22 - yield client.departures(eisenach, {when}) + await client.departures(eisenach, {when}) t.pass('did not fail') t.end()