db-vendo-client/format/location.js

18 lines
622 B
JavaScript
Raw Normal View History

'use strict'
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)
}
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)
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}`)
}
throw new Error(name + ': valid station, address or poi required.')
}
module.exports = formatLocation