mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
SNCB: normalize S-train line names
This commit is contained in:
parent
17031f3e11
commit
7d3107e6a7
1 changed files with 34 additions and 0 deletions
|
@ -3,6 +3,9 @@
|
||||||
const {readFileSync} = require('fs')
|
const {readFileSync} = require('fs')
|
||||||
const {join} = require('path')
|
const {join} = require('path')
|
||||||
const {Agent} = require('https')
|
const {Agent} = require('https')
|
||||||
|
const {strictEqual: eql} = require('assert')
|
||||||
|
const {parseHook} = require('../../lib/profile-hooks')
|
||||||
|
const parseLine = require('../../parse/line')
|
||||||
const products = require('./products')
|
const products = require('./products')
|
||||||
|
|
||||||
// `www.belgianrail.be:443` doesn't provide the necessary CA certificate
|
// `www.belgianrail.be:443` doesn't provide the necessary CA certificate
|
||||||
|
@ -21,6 +24,35 @@ const transformReqBody = ({opt}, body) => {
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: this is ugly
|
||||||
|
const lineNameWithoutFahrtNr = ({parsed}) => {
|
||||||
|
const {name, fahrtNr} = parsed
|
||||||
|
if (!name || !fahrtNr || !/s\d/i.test(name)) return parsed
|
||||||
|
const i = name.indexOf(fahrtNr)
|
||||||
|
if (i < 0) return parsed
|
||||||
|
|
||||||
|
if (
|
||||||
|
/\s/.test(name[i - 1] || '') && // space before
|
||||||
|
name.length === i + fahrtNr.length // nothing behind
|
||||||
|
) return {
|
||||||
|
...parsed,
|
||||||
|
name: name.slice(0, i - 1) + name.slice(i + fahrtNr.length + 1),
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
eql(lineNameWithoutFahrtNr({
|
||||||
|
parsed: {name: 'THA 123', fahrtNr: '123'}
|
||||||
|
}).name, 'THA 123')
|
||||||
|
eql(lineNameWithoutFahrtNr({
|
||||||
|
parsed: {name: 'S1 123', fahrtNr: '123'}
|
||||||
|
}).name, 'S1')
|
||||||
|
eql(lineNameWithoutFahrtNr({
|
||||||
|
parsed: {name: 'S1-123', fahrtNr: '123'}
|
||||||
|
}).name, 'S1-123')
|
||||||
|
eql(lineNameWithoutFahrtNr({
|
||||||
|
parsed: {name: 'S1 123a', fahrtNr: '123'}
|
||||||
|
}).name, 'S1 123a')
|
||||||
|
|
||||||
const sncbProfile = {
|
const sncbProfile = {
|
||||||
locale: 'fr-BE',
|
locale: 'fr-BE',
|
||||||
timezone: 'Europe/Brussels',
|
timezone: 'Europe/Brussels',
|
||||||
|
@ -31,6 +63,8 @@ const sncbProfile = {
|
||||||
|
|
||||||
products,
|
products,
|
||||||
|
|
||||||
|
parseLine: parseHook(parseLine, lineNameWithoutFahrtNr),
|
||||||
|
|
||||||
trip: true,
|
trip: true,
|
||||||
refreshJourney: true,
|
refreshJourney: true,
|
||||||
radar: true,
|
radar: true,
|
||||||
|
|
Loading…
Add table
Reference in a new issue