walking legs: expose distance

This commit is contained in:
Jannis R 2018-06-28 14:11:41 +02:00
parent 31973431ff
commit bb6e42a662
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 9 additions and 1 deletions

View file

@ -12,6 +12,7 @@ This version is not fully backwords-compatible. Check out [the migration guide](
- 021ae45 `journeys()`/`journeyLeg()`: leg stopovers: parse & expose platforms
- 84bce0c `arrivals()`/`departures()`: parse & expose platforms
- 85e0bdf `journeys()`: `startWithWalking` option with default `true`
- f6ae29c journey legs with `type: 'walking'` now have a `distance` in meters
### breaking changes 💥

View file

@ -80,6 +80,7 @@ const createParseJourneyLeg = (profile, opt, data) => {
if (pt.type === 'WALK') {
res.mode = 'walking'
res.public = true
res.distance = pt.gis && pt.gis.dist || null
} else if (pt.type === 'JNY') {
// todo: pull `public` value from `profile.products`
res.id = pt.jny.jid

View file

@ -191,7 +191,13 @@ const createValidateJourneyLeg = (cfg) => {
}
}
if (leg.mode !== 'walking') {
if (leg.mode === 'walking') {
if (leg.distance !== null) {
const msg = name + '.distance must be '
a.strictEqual(typeof leg.distance, 'number', msg + 'a number')
a.ok(leg.distance > 0, msg + '> 0')
}
} else {
const msg = name + '.direction must be a string'
a.strictEqual(typeof leg.direction, 'string', msg)
a.ok(leg.direction, name + '.direction must not be empty')