2018-04-17 18:43:42 +02:00
|
|
|
const formatLocation = (profile, l, name = 'location') => {
|
2024-02-06 22:58:49 +01:00
|
|
|
if ('string' === typeof l) {
|
|
|
|
return profile.formatStation(l);
|
|
|
|
}
|
2017-12-12 23:40:12 +01:00
|
|
|
if ('object' === typeof l && !Array.isArray(l)) {
|
2019-02-06 22:24:00 +01:00
|
|
|
if (l.type === 'station' || l.type === 'stop') {
|
2024-02-06 22:58:49 +01:00
|
|
|
return profile.formatStation(l.id);
|
|
|
|
}
|
|
|
|
if (l.poi) {
|
|
|
|
return profile.formatPoi(l);
|
|
|
|
}
|
|
|
|
if ('string' === typeof l.address) {
|
|
|
|
return profile.formatAddress(l);
|
|
|
|
}
|
|
|
|
if (!l.type) {
|
|
|
|
throw new TypeError(`missing ${name}.type`);
|
2019-02-06 22:24:00 +01:00
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
throw new TypeError(`invalid ${name}.type: ${l.type}`);
|
2017-11-12 19:15:13 +01:00
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
throw new TypeError(name + ': valid station, address or poi required.');
|
|
|
|
};
|
2017-11-12 19:15:13 +01:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
formatLocation,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|