2017-11-12 19:15:13 +01:00
|
|
|
'use strict'
|
|
|
|
|
2018-04-17 18:43:42 +02:00
|
|
|
const formatLocation = (profile, l, name = 'location') => {
|
2017-11-12 19:15:13 +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') {
|
|
|
|
return profile.formatStation(l.id)
|
|
|
|
}
|
2017-12-12 23:40:12 +01:00
|
|
|
if ('string' === typeof l.id) return profile.formatPoi(l)
|
|
|
|
if ('string' === typeof l.address) return profile.formatAddress(l)
|
2018-04-17 18:43:42 +02:00
|
|
|
if (!l.type) throw new Error(`missing ${name}.type`)
|
2018-05-03 10:29:43 +02:00
|
|
|
throw new Error(`invalid ${name}.type: ${l.type}`)
|
2017-11-12 19:15:13 +01:00
|
|
|
}
|
2018-04-17 18:43:42 +02:00
|
|
|
throw new Error(name + ': valid station, address or poi required.')
|
2017-11-12 19:15:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = formatLocation
|