@digitransit-store/digitransit-store-future-route
v2.0.8
Published
digitransit-store future-route module
Maintainers
Readme
@digitransit-store/digitransit-store-future-route
createUrl
Builds an itinerary summary URL for a future route entry.
Parameters
itemObject A FutureRoute item, as produced by addFutureRoute.pathOptsObject? Options for the generated path.pathOpts.itinerarySummaryPrefixstring? Path prefix to use instead of the default 'reitti'.
Examples
const route = {
properties: {
origin: { name: 'Pasila', localadmin: 'Helsinki', coordinates: { lat: 60.198828, lon: 24.933514 } },
destination: { name: 'Ilmala', localadmin: 'Helsinki', coordinates: { lat: 60.208466, lon: 24.919756 } },
arriveBy: true,
time: 1600866900,
},
};
createUrl(route);
//=> '/reitti/Pasila%2C%20Helsinki%3A%3A60.198828%2C24.933514/Ilmala%2C%20Helsinki%3A%3A60.208466%2C24.919756?time=1600866900&arriveBy=true'Returns string The itinerary summary URL, or '' if the item is missing an origin, destination or time.
addFutureRoute
Adds a future route to a collection of future routes, replacing any existing entry for the same origin/destination pair and dropping entries whose time has already passed.
Parameters
itemObject The route to add.collectionArray<Object>? The existing collection of future routes.
Examples
const newRoute = {
origin: { address: 'Pasila, Helsinki', coordinates: { lat: 60.198828, lon: 24.933514 } },
destination: { address: 'Myyrmäki, Vantaa', coordinates: { lat: 60.261238, lon: 24.854782 } },
arriveBy: false,
time: 1600888888,
};
addFutureRoute(newRoute, existingFutureRoutes);Returns Array<Object> The updated collection, sorted by time. If item.time is missing or cannot be parsed as a finite number, the collection is returned unchanged. If item.time is now or in the next five minutes, the item is not added - and any existing entry for the same origin/destination pair is removed - and the (possibly pruned) collection is returned instead.
This module is part of the Digitransit-ui project. It is maintained in the HSLdevcom/digitransit-ui repository, where you can create PRs and issues.
Installation
Install this module individually:
$ npm install @digitransit-store/digitransit-store-future-route