mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
formatters: add location, change address & poi
This commit is contained in:
parent
f86f908dcc
commit
c20fd35c67
5 changed files with 33 additions and 12 deletions
|
@ -2,14 +2,16 @@
|
|||
|
||||
const formatCoord = require('./coord')
|
||||
|
||||
const formatAddress = (latitude, longitude, name) => {
|
||||
if (!latitude || !longitude || !name) throw new Error('invalid address.')
|
||||
const formatAddress = (a) => {
|
||||
// todo: type-checking, better error msgs
|
||||
if (!a.latitude || !a.longitude || !a.name) throw new Error('invalid address.')
|
||||
|
||||
return {
|
||||
type: 'A',
|
||||
name,
|
||||
name: a.name,
|
||||
crd: {
|
||||
x: formatCoord(longitude),
|
||||
y: formatCoord(latitude)
|
||||
x: formatCoord(a.longitude),
|
||||
y: formatCoord(a.latitude)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,6 @@ module.exports = {
|
|||
station: require('./station'),
|
||||
address: require('./address'),
|
||||
poi: require('./poi'),
|
||||
location: require('./location'),
|
||||
locationFilter: require('./location-filter')
|
||||
}
|
||||
|
|
14
format/location.js
Normal file
14
format/location.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
'use strict'
|
||||
|
||||
const formatLocation = (profile, l) => {
|
||||
if ('string' === typeof l) return profile.formatStation(l)
|
||||
if ('object' === typeof l) {
|
||||
if (l.type === 'station') return profile.formatStation(l.id)
|
||||
if (l.type === 'poi') return profile.formatPoi(l)
|
||||
if (l.type === 'address') return profile.formatAddress(l)
|
||||
throw new Error('invalid location type: ' + l.type)
|
||||
}
|
||||
throw new Error('valid station, address or poi required.')
|
||||
}
|
||||
|
||||
module.exports = formatLocation
|
|
@ -2,15 +2,17 @@
|
|||
|
||||
const formatCoord = require('./coord')
|
||||
|
||||
const formatPoi = (latitude, longitude, id, name) => {
|
||||
if (!latitude || !longitude || !id || !name) throw new Error('invalid poi.')
|
||||
const formatPoi = (p) => {
|
||||
// todo: type-checking, better error msgs
|
||||
if (!p.latitude || !p.longitude || !p.id || !p.name) throw new Error('invalid poi.')
|
||||
|
||||
return {
|
||||
type: 'P',
|
||||
name,
|
||||
lid: 'L=' + id,
|
||||
name: p.name,
|
||||
lid: 'L=' + p.id,
|
||||
crd: {
|
||||
x: formatCoord(longitude),
|
||||
y: formatCoord(latitude)
|
||||
x: formatCoord(p.longitude),
|
||||
y: formatCoord(p.latitude)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ const formatLocationFilter = require('../format/location-filter')
|
|||
const formatPoi = require('../format/poi')
|
||||
const formatStation = require('../format/station')
|
||||
const formatTime = require('../format/time')
|
||||
const formatLocation = require('../format/location')
|
||||
|
||||
const id = x => x
|
||||
|
||||
|
@ -45,7 +46,8 @@ const defaultProfile = {
|
|||
formatLocationFilter,
|
||||
formatPoi,
|
||||
formatStation,
|
||||
formatTime
|
||||
formatTime,
|
||||
formatLocation
|
||||
}
|
||||
|
||||
module.exports = defaultProfile
|
||||
|
|
Loading…
Add table
Reference in a new issue