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; } };