db-vendo-client/format/location.js

18 lines
597 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)
2017-12-12 23:40:12 +01:00
if ('string' === typeof l.address) return profile.formatAddress(l)
2019-02-13 17:55:57 +01:00
if (!l.type) throw new TypeError(`missing ${name}.type`)
throw new TypeError(`invalid ${name}.type: ${l.type}`)
}
2019-02-13 17:55:57 +01:00
throw new TypeError(name + ': valid station, address or poi required.')
}
2022-05-07 16:17:37 +02:00
export {
formatLocation,
}