1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { getDS100byIBNR } from './ds100.js';
import { padZeros } from './helpers.js';
import { settingsState } from './settings.js';
export const formatPoint = point => {
switch (point.type) {
case 'stop':
case 'station':
let station = point.name;
if (settingsState.showDS100) {
const ds100 = getDS100byIBNR(point.id);
if (ds100 !== null) station += ` (${ds100})`;
}
return station;
case 'location':
if (point.address) return point.address;
return point.name;
default:
return '';
};
};
export const formatDuration = duration => {
const mins = duration / 60000;
const h = Math.floor(mins / 60);
const m = mins % 60;
if (h > 0) return h+'h '+m+'min';
return m+'min';
};
export const formatFromTo = obj => {
if (obj.type === 'stop' || obj.type === 'station')
return obj.id;
else if (obj.address)
return {
latitude: obj.latitude,
longitude: obj.longitude,
address: obj.address,
};
else
return {
id: obj.id,
latitude: obj.latitude,
longitude: obj.longitude,
};
};
export const formatPrice = price => {
if (!price) return '-';
const currencies = {
USD: '$',
EUR: '€',
GBP: '£'
};
let ret = currencies[price.currency] || price.currency;
ret += `${Math.floor(price.amount)}.${padZeros(price.amount * 100 % 100, 2)}`;
return ret;
};
export const formatTrainTypes = info => {
const counts = {};
info.sequence?.groups.forEach(group => {
const name = group.baureihe?.name;
if (!name) return;
counts[name] = (counts[name] ? counts[name] : 0) + 1;
});
return Object.entries(counts).map(([name, count]) => {
let text = "";
if (count > 1) text += `${count} x `;
text += name;
while (text.length < 12) {
text = ' ' + text + ' ';
}
return text;
}).join(" + ");
};
export const formatLineDisplayName = line => line?.name || line?.operator?.name || "???";
export const formatLineAdditionalName = line => {
if (!line.name) return null;
const splitName = line.name.split(' ');
if (splitName.length === 2 && line.fahrtNr && line.fahrtNr != splitName[1]) {
return `${splitName[0]} ${line.fahrtNr}`;
} else {
return null;
}
};