db-vendo-client/format/location.js

26 lines
640 B
JavaScript
Raw Permalink Normal View History

const formatLocation = (profile, l, name = 'location') => {
if ('string' === typeof l) {
return profile.formatStation(l);
}
2017-12-12 23:40:12 +01:00
if ('object' === typeof l && !Array.isArray(l)) {
if (l.type === 'station' || l.type === 'stop') {
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`);
}
throw new TypeError(`invalid ${name}.type: ${l.type}`);
}
throw new TypeError(name + ': valid station, address or poi required.');
};
2022-05-07 16:17:37 +02:00
export {
formatLocation,
};