2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2018-06-01 11:12:54 +02:00
|
|
|
const hints = Object.assign(Object.create(null), {
|
|
|
|
fb: {
|
|
|
|
type: 'hint',
|
2018-06-07 15:41:00 +02:00
|
|
|
code: 'bicycle-conveyance',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'bicycles conveyed'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
2018-06-30 18:02:48 +02:00
|
|
|
fr: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'bicycle-conveyance-reservation',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'bicycles conveyed, subject to reservation'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
2018-06-07 15:41:00 +02:00
|
|
|
nf: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'no-bicycle-conveyance',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'bicycles not conveyed'
|
2018-06-07 15:41:00 +02:00
|
|
|
},
|
2018-06-01 11:12:54 +02:00
|
|
|
k2: {
|
|
|
|
type: 'hint',
|
|
|
|
code: '2nd-class-only',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: '2. class only'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
|
|
|
eh: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'boarding-ramp',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'vehicle-mounted boarding ramp available'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
|
|
|
wv: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'wifi',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'WiFi available'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
2018-06-30 18:02:48 +02:00
|
|
|
wi: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'wifi',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'WiFi available'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
2018-06-01 11:12:54 +02:00
|
|
|
sn: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'snacks',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'snacks available for purchase'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
2018-06-30 18:02:48 +02:00
|
|
|
mb: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'snacks',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'snacks available for purchase'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
|
|
|
mp: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'snacks',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'snacks available for purchase at the seat'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
2018-06-01 11:12:54 +02:00
|
|
|
bf: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'barrier-free',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'barrier-free'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
2018-06-07 15:41:00 +02:00
|
|
|
rg: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'barrier-free-vehicle',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'barrier-free vehicle'
|
2018-06-07 15:41:00 +02:00
|
|
|
},
|
2018-06-01 11:12:54 +02:00
|
|
|
bt: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'on-board-bistro',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'Bordbistro available'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
|
|
|
br: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'on-board-restaurant',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'Bordrestaurant available'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
|
|
|
ki: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'childrens-area',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: `children's area available`
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
2018-06-30 18:02:48 +02:00
|
|
|
kr: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'kids-service',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'DB Kids Service available'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
2018-06-01 11:12:54 +02:00
|
|
|
ls: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'power-sockets',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'power sockets available'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
|
|
|
ev: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'replacement-service',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'replacement service'
|
2018-06-01 11:12:54 +02:00
|
|
|
},
|
|
|
|
kl: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'air-conditioned',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'air-conditioned vehicle'
|
2018-06-11 21:37:13 +02:00
|
|
|
},
|
|
|
|
r0: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'upward-escalator',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'upward escalator'
|
2018-06-11 21:37:13 +02:00
|
|
|
},
|
|
|
|
au: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'elevator',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'elevator available'
|
2018-06-25 13:59:42 +02:00
|
|
|
},
|
|
|
|
ck: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'komfort-checkin',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'Komfort-Checkin available'
|
2018-06-25 13:59:42 +02:00
|
|
|
},
|
|
|
|
it: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'ice-sprinter',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'ICE Sprinter service'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
|
|
|
rp: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'compulsory-reservation',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'compulsory seat reservation'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
|
|
|
sk: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'oversize-luggage-forbidden',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'oversize luggage not allowed'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
|
|
|
hu: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'animals-forbidden',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'animals not allowed, except guide dogs'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
|
|
|
ik: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'baby-cot-required',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'baby cot/child seat required'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
|
|
|
ee: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'on-board-entertainment',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'on-board entertainment available'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
|
|
|
toilet: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'toilet',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'toilet available'
|
2018-06-30 18:02:48 +02:00
|
|
|
},
|
|
|
|
iz: {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'intercity-2',
|
2018-06-30 18:04:44 +02:00
|
|
|
summary: 'Intercity 2'
|
2018-06-01 11:12:54 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-06-30 18:04:44 +02:00
|
|
|
const codesByIcon = Object.assign(Object.create(null), {
|
|
|
|
cancel: 'cancelled'
|
|
|
|
})
|
|
|
|
|
2017-11-12 01:23:34 +01:00
|
|
|
// todo: is passing in profile necessary?
|
2018-06-30 18:04:44 +02:00
|
|
|
const parseHint = (profile, h, icons) => {
|
2018-06-01 11:12:54 +02:00
|
|
|
// todo: C
|
2018-06-11 18:41:53 +02:00
|
|
|
|
|
|
|
const text = h.txtN && h.txtN.trim() || ''
|
2018-06-30 18:04:44 +02:00
|
|
|
const icon = 'number' === typeof h.icoX && icons[h.icoX] || null
|
|
|
|
const code = h.code || (icon && icon.res && codesByIcon[icon.res]) || null
|
2018-06-07 15:41:00 +02:00
|
|
|
|
2018-06-11 19:50:44 +02:00
|
|
|
if (h.type === 'M') {
|
|
|
|
return {
|
|
|
|
type: 'status',
|
|
|
|
summary: h.txtS && h.txtS.trim() || '',
|
2018-06-30 18:04:44 +02:00
|
|
|
code,
|
2018-06-11 19:50:44 +02:00
|
|
|
text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-07 15:41:00 +02:00
|
|
|
// todo: find sth more reliable than this
|
2018-06-11 18:41:53 +02:00
|
|
|
if (h.type === 'P' && text.toLowerCase() === 'journey cancelled') {
|
2018-06-07 15:41:00 +02:00
|
|
|
return {
|
|
|
|
type: 'status',
|
|
|
|
code: 'journey-cancelled',
|
2018-06-11 18:41:53 +02:00
|
|
|
text
|
2018-06-07 16:00:28 +02:00
|
|
|
// todo: `h.sIdx`
|
2018-06-07 15:41:00 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-11 18:41:53 +02:00
|
|
|
if (h.type === 'U' && text.toLowerCase() === 'stop cancelled') {
|
|
|
|
return {
|
|
|
|
type: 'status',
|
|
|
|
code: 'stop-cancelled',
|
|
|
|
text
|
|
|
|
}
|
|
|
|
}
|
2018-06-30 18:04:44 +02:00
|
|
|
if (h.type === 'G' && text.toLowerCase() === 'platform change') {
|
2018-06-11 18:41:53 +02:00
|
|
|
return {
|
|
|
|
type: 'status',
|
2018-06-30 18:04:44 +02:00
|
|
|
code: 'changed platform',
|
2018-06-11 18:41:53 +02:00
|
|
|
text
|
|
|
|
}
|
|
|
|
}
|
2018-06-07 16:00:28 +02:00
|
|
|
if (h.type === 'L') {
|
2018-06-01 11:12:54 +02:00
|
|
|
return {
|
|
|
|
type: 'status',
|
|
|
|
code: 'alternative-trip',
|
2018-06-11 18:41:53 +02:00
|
|
|
text,
|
2018-06-26 14:57:02 +02:00
|
|
|
tripId: h.jid
|
2018-06-01 11:12:54 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-07 16:00:28 +02:00
|
|
|
if (h.type === 'A') {
|
2018-06-30 18:04:44 +02:00
|
|
|
const hint = hints[h.code && h.code.trim().toLowerCase()]
|
|
|
|
if (hint) {
|
|
|
|
return Object.assign({text: h.txtN}, hint)
|
|
|
|
}
|
|
|
|
return null
|
2018-06-07 15:41:00 +02:00
|
|
|
}
|
2018-06-30 18:04:44 +02:00
|
|
|
|
|
|
|
if (h.type === 'D' || h.type === 'U' || h.type === 'R' || h.type === 'N') {
|
2018-06-01 11:12:54 +02:00
|
|
|
// todo: how can we identify the individual types?
|
|
|
|
return {
|
|
|
|
type: 'status',
|
2018-06-30 18:04:44 +02:00
|
|
|
code,
|
2018-06-11 18:41:53 +02:00
|
|
|
text
|
2018-06-01 11:12:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2018-06-07 16:00:28 +02:00
|
|
|
module.exports = parseHint
|