mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
validate opt.when 💥
This commit is contained in:
parent
0840d69ee9
commit
0ef03015e0
1 changed files with 8 additions and 4 deletions
12
index.js
12
index.js
|
@ -31,7 +31,8 @@ const createClient = (profile, request = _request) => {
|
||||||
direction: null, // only show departures heading to this station
|
direction: null, // only show departures heading to this station
|
||||||
duration: 10 // show departures for the next n minutes
|
duration: 10 // show departures for the next n minutes
|
||||||
}, opt)
|
}, opt)
|
||||||
opt.when = opt.when || new Date()
|
opt.when = new Date(opt.when || Date.now())
|
||||||
|
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
||||||
const products = profile.formatProductsFilter(opt.products || {})
|
const products = profile.formatProductsFilter(opt.products || {})
|
||||||
|
|
||||||
const dir = opt.direction ? profile.formatStation(opt.direction) : null
|
const dir = opt.direction ? profile.formatStation(opt.direction) : null
|
||||||
|
@ -96,7 +97,8 @@ const createClient = (profile, request = _request) => {
|
||||||
polylines: false // return leg shapes?
|
polylines: false // return leg shapes?
|
||||||
}, opt)
|
}, opt)
|
||||||
if (opt.via) opt.via = profile.formatLocation(profile, opt.via)
|
if (opt.via) opt.via = profile.formatLocation(profile, opt.via)
|
||||||
opt.when = opt.when || new Date()
|
opt.when = new Date(opt.when || Date.now())
|
||||||
|
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
||||||
|
|
||||||
const filters = [
|
const filters = [
|
||||||
profile.formatProductsFilter(opt.products || {})
|
profile.formatProductsFilter(opt.products || {})
|
||||||
|
@ -281,7 +283,8 @@ const createClient = (profile, request = _request) => {
|
||||||
passedStations: true, // return stations on the way?
|
passedStations: true, // return stations on the way?
|
||||||
polyline: false
|
polyline: false
|
||||||
}, opt)
|
}, opt)
|
||||||
opt.when = opt.when || new Date()
|
opt.when = new Date(opt.when || Date.now())
|
||||||
|
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
||||||
|
|
||||||
return request(profile, {
|
return request(profile, {
|
||||||
cfg: {polyEnc: 'GPA'},
|
cfg: {polyEnc: 'GPA'},
|
||||||
|
@ -326,7 +329,8 @@ const createClient = (profile, request = _request) => {
|
||||||
products: null, // optionally an object of booleans
|
products: null, // optionally an object of booleans
|
||||||
polylines: false // return a track shape for each vehicle?
|
polylines: false // return a track shape for each vehicle?
|
||||||
}, opt || {})
|
}, opt || {})
|
||||||
opt.when = opt.when || new Date()
|
opt.when = new Date(opt.when || Date.now())
|
||||||
|
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
||||||
|
|
||||||
const durationPerStep = opt.duration / Math.max(opt.frames, 1) * 1000
|
const durationPerStep = opt.duration / Math.max(opt.frames, 1) * 1000
|
||||||
return request(profile, {
|
return request(profile, {
|
||||||
|
|
Loading…
Add table
Reference in a new issue