@opentripplanner/core-utils 5.0.3-alpha.1 → 7.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/esm/itinerary.js +74 -11
  2. package/esm/itinerary.js.map +1 -1
  3. package/esm/map.js +20 -239
  4. package/esm/map.js.map +1 -1
  5. package/esm/query.js +14 -11
  6. package/esm/query.js.map +1 -1
  7. package/esm/time.js +5 -56
  8. package/esm/time.js.map +1 -1
  9. package/lib/itinerary.d.ts +14 -7
  10. package/lib/itinerary.d.ts.map +1 -1
  11. package/lib/itinerary.js +79 -65
  12. package/lib/itinerary.js.map +1 -1
  13. package/lib/map.d.ts +4 -13
  14. package/lib/map.d.ts.map +1 -1
  15. package/lib/map.js +18 -251
  16. package/lib/map.js.map +1 -1
  17. package/lib/query.js +11 -15
  18. package/lib/query.js.map +1 -1
  19. package/lib/time.d.ts +1 -16
  20. package/lib/time.d.ts.map +1 -1
  21. package/lib/time.js +4 -72
  22. package/lib/time.js.map +1 -1
  23. package/package.json +4 -5
  24. package/src/__tests__/__snapshots__/itinerary.js.snap +2 -38
  25. package/src/__tests__/__snapshots__/time.js.snap +7 -13
  26. package/src/__tests__/itinerary.js +6 -29
  27. package/src/__tests__/time.js +7 -27
  28. package/src/itinerary.ts +72 -27
  29. package/src/map.ts +19 -287
  30. package/src/query.js +19 -16
  31. package/src/time.ts +11 -76
  32. package/tsconfig.tsbuildinfo +1381 -1288
  33. package/esm/deprecated-with-types.js +0 -47
  34. package/esm/deprecated-with-types.js.map +0 -1
  35. package/esm/deprecated.js +0 -325
  36. package/esm/deprecated.js.map +0 -1
  37. package/lib/deprecated-with-types.d.ts +0 -23
  38. package/lib/deprecated-with-types.d.ts.map +0 -1
  39. package/lib/deprecated-with-types.js +0 -61
  40. package/lib/deprecated-with-types.js.map +0 -1
  41. package/lib/deprecated.js +0 -355
  42. package/lib/deprecated.js.map +0 -1
  43. package/src/__tests__/__mocks__/multi-currency-itinerary.json +0 -1728
  44. package/src/deprecated-with-types.ts +0 -62
  45. package/src/deprecated.js +0 -334
package/esm/query.js CHANGED
@@ -7,15 +7,15 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
7
7
 
8
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
9
9
 
10
- import moment from "moment";
10
+ import { format, isMatch, parse } from "date-fns";
11
11
  import getGeocoder from "@opentripplanner/geocoder/lib";
12
12
  import qs from "qs";
13
13
  import { getTransitModes, hasCar, isAccessMode } from "./itinerary";
14
- import { stringToCoords } from "./map";
14
+ import { coordsToString, stringToCoords } from "./map";
15
15
  import queryParams from "./query-params";
16
- import { getCurrentTime, getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } from "./time";
17
- import { coordsToString, summarizeQuery } from "./deprecated";
18
- export { summarizeQuery };
16
+ import { getCurrentTime, getCurrentDate, OTP_API_TIME_FORMAT, OTP_API_DATE_FORMAT_DATE_FNS } from "./time"; // import { coordsToString, summarizeQuery } from "./deprecated";
17
+ // export { summarizeQuery };
18
+
19
19
  /* The list of default parameters considered in the settings panel */
20
20
 
21
21
  export var defaultParams = ["wheelchair", "maxWalkDistance", "walkReluctance", "maxWalkTime", "walkSpeed", "maxBikeDistance", "maxBikeTime", "bikeSpeed", "optimize", "optimizeBike", "maxEScooterDistance", "watts"];
@@ -356,8 +356,11 @@ export function planParamsToQuery(params) {
356
356
 
357
357
  case "time":
358
358
  {
359
- var parsedTime = moment(params.time, TIME_FORMATS);
360
- query.time = parsedTime.isValid() ? parsedTime.format(OTP_API_TIME_FORMAT) : getCurrentTime();
359
+ // Match one of the supported time formats
360
+ var matchedTimeFormat = TIME_FORMATS.find(function (timeFormat) {
361
+ return isMatch(params.time, timeFormat);
362
+ });
363
+ query.time = matchedTimeFormat ? format(parse(params.time, matchedTimeFormat, new Date()), OTP_API_TIME_FORMAT) : getCurrentTime();
361
364
  }
362
365
  break;
363
366
 
@@ -482,8 +485,8 @@ export function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
482
485
  } // check date/time validity; ignore both if either is invalid
483
486
 
484
487
 
485
- var dateValid = moment(params.date, OTP_API_DATE_FORMAT).isValid();
486
- var timeValid = moment(params.time, OTP_API_TIME_FORMAT).isValid();
488
+ var dateValid = isMatch(params.date, OTP_API_DATE_FORMAT_DATE_FNS);
489
+ var timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);
487
490
 
488
491
  if (!dateValid || !timeValid) {
489
492
  delete params.time;
@@ -504,8 +507,8 @@ export function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
504
507
 
505
508
  } else {
506
509
  // check start and end time validity; ignore both if either is invalid
507
- var startTimeValid = moment(params.startTime, OTP_API_TIME_FORMAT).isValid();
508
- var endTimeValid = moment(params.endTime, OTP_API_TIME_FORMAT).isValid();
510
+ var startTimeValid = isMatch(params.startTime, OTP_API_TIME_FORMAT);
511
+ var endTimeValid = isMatch(params.endTime, OTP_API_TIME_FORMAT);
509
512
 
510
513
  if (!startTimeValid || !endTimeValid) {
511
514
  delete params.startTimeValid;
package/esm/query.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/query.js"],"names":["moment","getGeocoder","qs","getTransitModes","hasCar","isAccessMode","stringToCoords","queryParams","getCurrentTime","getCurrentDate","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","coordsToString","summarizeQuery","defaultParams","TIME_FORMATS","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","length","firstAccess","find","push","getUrlParams","parse","window","location","href","split","getOtpUrlParams","Object","keys","key","startsWith","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","from","to","getDefaultQueryParamValue","param","getDefaultQuery","config","defaultQuery","routingType","qp","forEach","name","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","reduce","prev","cur","newModes","expandOtpFlexMode","mode","map","join","isNotDefaultQuery","activeModes","sort","defaultModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoder","search","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","lat","lon","queryParamToLocation","planParamsToQuery","params","fromPlace","toPlace","arriveBy","parsedTime","isValid","format","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","indexOf","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","reducedMode"],"mappings":";;;;;;;;;AAAA,OAAOA,MAAP,MAAmB,QAAnB;AACA,OAAOC,WAAP,MAAwB,+BAAxB;AACA,OAAOC,EAAP,MAAe,IAAf;AAEA,SAASC,eAAT,EAA0BC,MAA1B,EAAkCC,YAAlC,QAAsD,aAAtD;AACA,SAASC,cAAT,QAA+B,OAA/B;AACA,OAAOC,WAAP,MAAwB,gBAAxB;AACA,SACEC,cADF,EAEEC,cAFF,EAGEC,mBAHF,EAIEC,mBAJF,QAKO,QALP;AAOA,SAASC,cAAT,EAAyBC,cAAzB,QAA+C,cAA/C;AAEA,SAASA,cAAT;AAEA;;AAEA,OAAO,IAAMC,aAAa,GAAG,CAC3B,YAD2B,EAE3B,iBAF2B,EAG3B,gBAH2B,EAI3B,aAJ2B,EAK3B,WAL2B,EAM3B,iBAN2B,EAO3B,aAP2B,EAQ3B,WAR2B,EAS3B,UAT2B,EAU3B,cAV2B,EAW3B,qBAX2B,EAY3B,OAZ2B,CAAtB;AAeP;AACA;A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GAAhD,CAApB;AACA4B,IAAAA,MAAM,CAAC9B,IAAP,GAAcD,iBAAiB,CAAC6D,WAAD,CAA/B;AACD;;AAED,SAAO9B,MAAP;AACD","sourcesContent":["import moment from \"moment\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport { getTransitModes, hasCar, isAccessMode } from \"./itinerary\";\nimport { stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_DATE_FORMAT,\n OTP_API_TIME_FORMAT\n} from \"./time\";\n\nimport { coordsToString, summarizeQuery } from \"./deprecated\";\n\nexport { summarizeQuery };\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"walkReluctance\",\n \"maxWalkTime\",\n \"walkSpeed\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\",\n OTP_API_TIME_FORMAT // 'HH:mm'\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n return qs.parse(window.location.href.split(\"?\")[1]);\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes) {\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the exapnded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(query.mode.split(\",\").sort());\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @return {Location}\n */\nasync function getFirstGeocodeResult(text, geocoderConfig) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder.search({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(value, geocoderConfig);\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n const parsedTime = moment(params.time, TIME_FORMATS);\n query.time = parsedTime.isValid()\n ? parsedTime.format(OTP_API_TIME_FORMAT)\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = moment(params.date, OTP_API_DATE_FORMAT).isValid();\n const timeValid = moment(params.time, OTP_API_TIME_FORMAT).isValid();\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = moment(\n params.startTime,\n OTP_API_TIME_FORMAT\n ).isValid();\n const endTimeValid = moment(params.endTime, OTP_API_TIME_FORMAT).isValid();\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n if (params.mode) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"file":"query.js"}
1
+ {"version":3,"sources":["../src/query.js"],"names":["format","isMatch","parse","getGeocoder","qs","getTransitModes","hasCar","isAccessMode","coordsToString","stringToCoords","queryParams","getCurrentTime","getCurrentDate","OTP_API_TIME_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","defaultParams","TIME_FORMATS","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","length","firstAccess","find","push","getUrlParams","window","location","href","split","getOtpUrlParams","Object","keys","key","startsWith","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","from","to","getDefaultQueryParamValue","param","getDefaultQuery","config","defaultQuery","routingType","qp","forEach","name","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","reduce","prev","cur","newModes","expandOtpFlexMode","mode","map","join","isNotDefaultQuery","activeModes","sort","defaultModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoder","search","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","lat","lon","queryParamToLocation","planParamsToQuery","params","fromPlace","toPlace","arriveBy","matchedTimeFormat","timeFormat","Date","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","indexOf","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","reducedMode"],"mappings":";;;;;;;;;AAAA,SAASA,MAAT,EAAiBC,OAAjB,EAA0BC,KAA1B,QAAuC,UAAvC;AACA,OAAOC,WAAP,MAAwB,+BAAxB;AACA,OAAOC,EAAP,MAAe,IAAf;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G9H,OAAO,CAACkG,MAAM,CAAC6B,OAAR,EAAiBnH,mBAAjB,CAA5B;;AAEA,QAAI,CAACgH,cAAD,IAAmB,CAACE,YAAxB,EAAsC;AACpC,aAAO5B,MAAM,CAAC0B,cAAd;AACA,aAAO1B,MAAM,CAAC4B,YAAd;AACD;AACF,GA1E2E,CA4E5E;AAEA;;;AACA,MAAIzH,MAAM,CAAC6F,MAAM,CAAC9B,IAAR,CAAV,EAAyB;AACvB8B,IAAAA,MAAM,CAAC9B,IAAP,IAAe,OAAf;AACD,GAjF2E,CAmF5E;;;AACA,MAAI8B,MAAM,CAAC9B,IAAX,EAAiB;AACf;AACA,QAAM4D,WAAW,GAAGnE,kBAAkB,CAACqC,MAAM,CAAC9B,IAAP,CAAYnC,KAAZ,CAAkB,GAAlB,CAAD,CAAlB,CAA2CqC,IAA3C,CAAgD,GAAhD,CAApB;AACA4B,IAAAA,MAAM,CAAC9B,IAAP,GAAcD,iBAAiB,CAAC6D,WAAD,CAA/B;AACD;;AAED,SAAO9B,MAAP;AACD","sourcesContent":["import { format, isMatch, parse } from \"date-fns\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport { getTransitModes, hasCar, isAccessMode } from \"./itinerary\";\nimport { coordsToString, stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_TIME_FORMAT,\n OTP_API_DATE_FORMAT_DATE_FNS\n} from \"./time\";\n\n// import { coordsToString, summarizeQuery } from \"./deprecated\";\n\n// export { summarizeQuery };\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"walkReluctance\",\n \"maxWalkTime\",\n \"walkSpeed\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\",\n OTP_API_TIME_FORMAT // 'HH:mm'\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n return qs.parse(window.location.href.split(\"?\")[1]);\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes) {\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the exapnded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(query.mode.split(\",\").sort());\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @return {Location}\n */\nasync function getFirstGeocodeResult(text, geocoderConfig) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder.search({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(value, geocoderConfig);\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n // Match one of the supported time formats\n const matchedTimeFormat = TIME_FORMATS.find(timeFormat =>\n isMatch(params.time, timeFormat)\n );\n query.time = matchedTimeFormat\n ? format(\n parse(params.time, matchedTimeFormat, new Date()),\n OTP_API_TIME_FORMAT\n )\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = isMatch(params.date, OTP_API_DATE_FORMAT_DATE_FNS);\n const timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = isMatch(params.startTime, OTP_API_TIME_FORMAT);\n const endTimeValid = isMatch(params.endTime, OTP_API_TIME_FORMAT);\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n if (params.mode) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"file":"query.js"}
package/esm/time.js CHANGED
@@ -1,9 +1,5 @@
1
- import { startOfDay, add, format, formatDuration as dateFnsFormatDuration } from "date-fns";
2
- import { utcToZonedTime } from "date-fns-tz";
3
- /* eslint-disable import/no-cycle */
4
-
5
- import { formatTime, formatDurationWithSeconds, formatDuration } from "./deprecated-with-types";
6
- export { formatTime, formatDuration, formatDurationWithSeconds }; // special constants for making sure the following date format is always sent to
1
+ import { startOfDay, add, format } from "date-fns";
2
+ import { utcToZonedTime } from "date-fns-tz"; // special constants for making sure the following date format is always sent to
7
3
  // OTP regardless of whatever the user has configured as the display format
8
4
 
9
5
  export var OTP_API_DATE_FORMAT = "YYYY-MM-DD"; // Date-Fns uses a different string format than moment.js
@@ -11,51 +7,6 @@ export var OTP_API_DATE_FORMAT = "YYYY-MM-DD"; // Date-Fns uses a different stri
11
7
 
12
8
  export var OTP_API_DATE_FORMAT_DATE_FNS = "yyyy-MM-dd";
13
9
  export var OTP_API_TIME_FORMAT = "HH:mm";
14
- /**
15
- * To ease the transition away from moment.js, this method uses date-fns to format durations
16
- * the way moment.js did.
17
- * @param {number} seconds The number of seconds to format
18
- * @param {boolean} showSeconds Whether to render seconds or not
19
- * @param {boolean} localize If true, will create output like moment.js using date-fns locale.
20
- * Otherwise, uses date-fns default
21
- * @returns Formatted duration
22
- */
23
-
24
- export function formatDurationLikeMoment(seconds, showSeconds) {
25
- var localize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
26
- enabled: true,
27
- code: "en-US"
28
- };
29
-
30
- // date-fns doesn't do this automatically
31
- if (!showSeconds && seconds < 60 || seconds === 0) {
32
- return "0 min";
33
- }
34
-
35
- var hours = Math.floor(seconds / 3600);
36
- var minutes = Math.floor((seconds - hours * 3600) / 60);
37
- var secondsLeftOver = showSeconds ? seconds - hours * 3600 - minutes * 60 : 0;
38
- var specLookup = {
39
- xHours: "hr",
40
- xMinutes: "min",
41
- xSeconds: "sec"
42
- };
43
- var locale = localize ? {
44
- // Maintain backwards compatibility when called with localize=true
45
- code: (localize === null || localize === void 0 ? void 0 : localize.code) || "en-US",
46
- formatDistance: function formatDistance(spec, val) {
47
- return "".concat(val, " ").concat(specLookup[spec]);
48
- }
49
- } : undefined;
50
- return dateFnsFormatDuration({
51
- hours: hours,
52
- minutes: minutes,
53
- seconds: secondsLeftOver
54
- }, {
55
- format: ["hours", "minutes", "seconds"],
56
- locale: locale
57
- });
58
- }
59
10
  /**
60
11
  * Breaks up a duration in seconds into hours, minutes, and seconds.
61
12
  * @param {number} seconds The number of seconds to break up
@@ -63,12 +14,10 @@ export function formatDurationLikeMoment(seconds, showSeconds) {
63
14
  */
64
15
 
65
16
  export function toHoursMinutesSeconds(seconds) {
66
- var hours = Math.floor(seconds / 3600);
67
- var minutes = Math.floor((seconds - hours * 3600) / 60);
68
17
  return {
69
- hours: hours,
70
- minutes: minutes,
71
- seconds: seconds - hours * 3600 - minutes * 60
18
+ hours: Math.floor(seconds / 3600),
19
+ minutes: Math.floor(seconds / 60) % 60,
20
+ seconds: seconds % 60
72
21
  };
73
22
  }
74
23
  /**
package/esm/time.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/time.ts"],"names":["startOfDay","add","format","formatDuration","dateFnsFormatDuration","utcToZonedTime","formatTime","formatDurationWithSeconds","OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","formatDurationLikeMoment","seconds","showSeconds","localize","enabled","code","hours","Math","floor","minutes","secondsLeftOver","specLookup","xHours","xMinutes","xSeconds","locale","formatDistance","spec","val","undefined","toHoursMinutesSeconds","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":"AACA,SACEA,UADF,EAEEC,GAFF,EAGEC,MAHF,EAIEC,cAAc,IAAIC,qBAJpB,QAKO,UALP;AAMA,SAASC,cAAT,QAA+B,aAA/B;AAEA;;AACA,SACEC,UADF,EAEEC,yBAFF,EAGEJ,cAHF,QAIO,yBAJP;AAMA,SAASG,UAAT,EAAqBH,cAArB,EAAqCI,yBAArC,G,CAEA;AACA;;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAA5B,C,CACP;AACA;;AACA,OAAO,IAAMC,4BAA4B,GAAG,YAArC;AACP,OAAO,IAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,wBAAT,CACLC,OADK,EAELC,WAFK,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AGG;AACR,MAAMU,IAAI,GAAG5C,GAAG,CAACD,UAAU,CAAC,IAAI8C,IAAJ,EAAD,CAAX,EAAyB;AAAElC,IAAAA,OAAO,EAAPA;AAAF,GAAzB,CAAhB;AACA,SAAOV,MAAM,CAAC2C,IAAD,EAAOV,UAAP,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASY,eAAT,GAAqE;AAAA;;AAAA,MAA5CC,gBAA4C,uEAAzB,eAAyB;AAC1E,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA7B,EAAqC,OAAOF,OAAO,CAACC,GAAR,CAAYE,EAAnB;AACrC,SAAO,UAAAC,IAAI,UAAJ,sCAAMC,cAAN,GAAuBC,eAAvB,GAAyCC,QAAzC,KAAqDR,gBAA5D;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASS,cAAT,GAA8D;AAAA,MAAtCC,QAAsC,uEAA3BX,eAAe,EAAY;AACnE,SAAO7C,MAAM,CAACG,cAAc,CAACyC,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CAAf,EAAuChD,mBAAvC,CAAb;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASkD,cAAT,GAA8D;AAAA,MAAtCF,QAAsC,uEAA3BX,eAAe,EAAY;AACnE,SAAO7C,MAAM,CACXG,cAAc,CAACyC,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CADH,EAEXjD,4BAFW,CAAb;AAID","sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport {\n startOfDay,\n add,\n format,\n formatDuration as dateFnsFormatDuration\n} from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n/* eslint-disable import/no-cycle */\nimport {\n formatTime,\n formatDurationWithSeconds,\n formatDuration\n} from \"./deprecated-with-types\";\n\nexport { formatTime, formatDuration, formatDurationWithSeconds };\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * To ease the transition away from moment.js, this method uses date-fns to format durations\n * the way moment.js did.\n * @param {number} seconds The number of seconds to format\n * @param {boolean} showSeconds Whether to render seconds or not\n * @param {boolean} localize If true, will create output like moment.js using date-fns locale.\n * Otherwise, uses date-fns default\n * @returns Formatted duration\n */\nexport function formatDurationLikeMoment(\n seconds: number,\n showSeconds: boolean,\n localize: { enabled: boolean; code: string } = {\n enabled: true,\n code: \"en-US\"\n }\n): string {\n // date-fns doesn't do this automatically\n if ((!showSeconds && seconds < 60) || seconds === 0) {\n return \"0 min\";\n }\n\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n const secondsLeftOver = showSeconds\n ? seconds - hours * 3600 - minutes * 60\n : 0;\n const specLookup = {\n xHours: \"hr\",\n xMinutes: \"min\",\n xSeconds: \"sec\"\n };\n const locale = localize\n ? {\n // Maintain backwards compatibility when called with localize=true\n code: localize?.code || \"en-US\",\n formatDistance: (spec, val) => {\n return `${val} ${specLookup[spec]}`;\n }\n }\n : undefined;\n\n return dateFnsFormatDuration(\n {\n hours,\n minutes,\n seconds: secondsLeftOver\n },\n {\n format: [\"hours\", \"minutes\", \"seconds\"],\n locale\n }\n );\n}\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(seconds) {\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n return {\n hours,\n minutes,\n seconds: seconds - hours * 3600 - minutes * 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
1
+ {"version":3,"sources":["../src/time.ts"],"names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":"AACA,SAASA,UAAT,EAAqBC,GAArB,EAA0BC,MAA1B,QAAwC,UAAxC;AACA,SAASC,cAAT,QAA+B,aAA/B,C,CAEA;AACA;;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAA5B,C,CACP;AACA;;AACA,OAAO,IAAMC,4BAA4B,GAAG,YAArC;AACP,OAAO,IAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CACLC,OADK,EAML;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEC,IAAI,CAACC,KAAL,CAAWH,OAAO,GAAG,IAArB,CADF;AAELI,IAAAA,OAAO,EAAEF,IAAI,CAACC,KAAL,CAAWH,OAAO,GAAG,EAArB,IAA2B,EAF/B;AAGLA,IAAAA,OAAO,EAAEA,OAAO,GAAG;AAHd,GAAP;AAKD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASK,aAAT,CAAuBC,MAAvB,EAA+C;AAAA;;AACpD,SAAO,CAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,gCAAAA,MAAM,CAAEC,QAAR,sEAAkBC,UAAlB,KAAgCV,mBAAvC;AACD;AAED,OAAO,SAASW,aAAT,CAAuBH,MAAvB,EAA+C;AAAA;;AACpD,SAAO,CAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,iCAAAA,MAAM,CAAEC,QAAR,wEAAkBG,UAAlB,KAAgCd,mBAAvC;AACD;AAED,OAAO,SAASe,iBAAT,CAA2BL,MAA3B,EAAmD;AAAA;;AACxD,SAAO,CAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,iCAAAA,MAAM,CAAEC,QAAR,wEAAkBK,cAAlB,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planner/types\";\nimport { startOfDay, add, format } from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
@@ -1,6 +1,4 @@
1
- import { Company, Config, ElevationProfile, FlexBookingInfo, Itinerary, LatLngArray, Leg, Step } from "@opentripplanner/types";
2
- import { calculateFares, getLegModeLabel, getModeForPlace, getPlaceName, getStepDirection, getStepInstructions, getStepStreetName, getTimeZoneOffset, getTransitFare } from "./deprecated";
3
- export { calculateFares, getLegModeLabel, getModeForPlace, getPlaceName, getStepDirection, getStepInstructions, getStepStreetName, getTimeZoneOffset, getTransitFare };
1
+ import { Company, Config, ElevationProfile, FlexBookingInfo, Itinerary, LatLngArray, Leg, Money, Step, TncFare } from "@opentripplanner/types";
4
2
  export declare const transitModes: string[];
5
3
  /**
6
4
  * @param {config} config OTP-RR configuration object
@@ -105,9 +103,18 @@ export declare function calculatePhysicalActivity(itinerary: Itinerary): {
105
103
  caloriesBurned: number;
106
104
  walkDuration: number;
107
105
  };
108
- export declare function calculateTncFares(itinerary: any): {
109
- maxTNCFare: any;
110
- minTNCFare: any;
111
- tncCurrencyCode: any;
106
+ /**
107
+ * For an itinerary, calculates the TNC fares and returns an object with
108
+ * these values and currency info.
109
+ * It is assumed that the same currency is used for all TNC legs.
110
+ */
111
+ export declare function calculateTncFares(itinerary: Itinerary): TncFare;
112
+ /**
113
+ * For a given fare component (either total fare or component parts), returns
114
+ * an object with the fare value (in cents).
115
+ */
116
+ export declare function getTransitFare(fareComponent: Money): {
117
+ currencyCode: string;
118
+ transitFare: number;
112
119
  };
113
120
  //# sourceMappingURL=itinerary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,WAAW,EACX,GAAG,EACH,IAAI,EACL,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACf,CAAC;AAGF,eAAO,MAAM,YAAY,UAOxB,CAAC;AAEF;;;GAGG;AAEH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAOxD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAEvD;AACD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAErD;AACD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAExC;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAEvE;AACD,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAElE;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO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AmB/D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,aAAa,EAAE,KAAK,GACnB;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAcA"}
package/lib/itinerary.js CHANGED
@@ -38,68 +38,38 @@ exports.getCompaniesLabelFromNetworks = getCompaniesLabelFromNetworks;
38
38
  exports.getTNCLocation = getTNCLocation;
39
39
  exports.calculatePhysicalActivity = calculatePhysicalActivity;
40
40
  exports.calculateTncFares = calculateTncFares;
41
- Object.defineProperty(exports, "calculateFares", {
42
- enumerable: true,
43
- get: function () {
44
- return _deprecated.calculateFares;
45
- }
46
- });
47
- Object.defineProperty(exports, "getLegModeLabel", {
48
- enumerable: true,
49
- get: function () {
50
- return _deprecated.getLegModeLabel;
51
- }
52
- });
53
- Object.defineProperty(exports, "getModeForPlace", {
54
- enumerable: true,
55
- get: function () {
56
- return _deprecated.getModeForPlace;
57
- }
58
- });
59
- Object.defineProperty(exports, "getPlaceName", {
60
- enumerable: true,
61
- get: function () {
62
- return _deprecated.getPlaceName;
63
- }
64
- });
65
- Object.defineProperty(exports, "getStepDirection", {
66
- enumerable: true,
67
- get: function () {
68
- return _deprecated.getStepDirection;
69
- }
70
- });
71
- Object.defineProperty(exports, "getStepInstructions", {
72
- enumerable: true,
73
- get: function () {
74
- return _deprecated.getStepInstructions;
75
- }
76
- });
77
- Object.defineProperty(exports, "getStepStreetName", {
78
- enumerable: true,
79
- get: function () {
80
- return _deprecated.getStepStreetName;
81
- }
82
- });
83
- Object.defineProperty(exports, "getTimeZoneOffset", {
84
- enumerable: true,
85
- get: function () {
86
- return _deprecated.getTimeZoneOffset;
87
- }
88
- });
89
- Object.defineProperty(exports, "getTransitFare", {
90
- enumerable: true,
91
- get: function () {
92
- return _deprecated.getTransitFare;
93
- }
94
- });
41
+ exports.getTransitFare = getTransitFare;
95
42
  exports.transitModes = void 0;
96
43
 
97
44
  var _polyline = _interopRequireDefault(require("@mapbox/polyline"));
98
45
 
99
46
  var _along = _interopRequireDefault(require("@turf/along"));
100
47
 
101
- var _deprecated = require("./deprecated");
102
-
48
+ /*
49
+ import {
50
+ // calculateFares,
51
+ // getLegModeLabel,
52
+ // getModeForPlace,
53
+ // getPlaceName,
54
+ // getStepDirection,
55
+ // getStepInstructions,
56
+ // getStepStreetName,
57
+ // getTimeZoneOffset,
58
+ // getTransitFare
59
+ } from "./deprecated";
60
+
61
+ export {
62
+ // calculateFares,
63
+ // getLegModeLabel,
64
+ // getModeForPlace,
65
+ // getPlaceName,
66
+ // getStepDirection,
67
+ // getStepInstructions,
68
+ // getStepStreetName,
69
+ // getTimeZoneOffset,
70
+ // getTransitFare
71
+ };
72
+ */
103
73
  // All OTP transit modes
104
74
  const transitModes = ["TRAM", "BUS", "SUBWAY", "FERRY", "RAIL", "GONDOLA"];
105
75
  /**
@@ -496,19 +466,63 @@ function calculatePhysicalActivity(itinerary) {
496
466
  walkDuration
497
467
  };
498
468
  }
469
+ /**
470
+ * For an itinerary, calculates the TNC fares and returns an object with
471
+ * these values and currency info.
472
+ * It is assumed that the same currency is used for all TNC legs.
473
+ */
474
+
499
475
 
500
476
  function calculateTncFares(itinerary) {
501
- // TODO: don't rely on deprecated methods!
502
- // At the moment this is safe as none of these exported variables contain strings
503
- const {
504
- maxTNCFare,
505
- minTNCFare,
506
- tncCurrencyCode
507
- } = (0, _deprecated.calculateFares)(itinerary, true);
477
+ let minTNCFare = 0;
478
+ let maxTNCFare = 0;
479
+ let currencyCode;
480
+ itinerary.legs.forEach(({
481
+ hailedCar,
482
+ mode,
483
+ tncData
484
+ }) => {
485
+ if (mode === "CAR" && hailedCar && tncData) {
486
+ const {
487
+ currency,
488
+ maxCost,
489
+ minCost
490
+ } = tncData;
491
+ minTNCFare += minCost;
492
+ maxTNCFare += maxCost; // Assumes a single currency for entire itinerary.
493
+
494
+ currencyCode = currency;
495
+ }
496
+ });
508
497
  return {
498
+ currencyCode,
509
499
  maxTNCFare,
510
- minTNCFare,
511
- tncCurrencyCode
500
+ minTNCFare
501
+ };
502
+ }
503
+ /**
504
+ * For a given fare component (either total fare or component parts), returns
505
+ * an object with the fare value (in cents).
506
+ */
507
+
508
+
509
+ function getTransitFare(fareComponent) {
510
+ // Default values (if fare component is not valid).
511
+ let transitFare = 0;
512
+ let currencyCode = "USD";
513
+
514
+ if (fareComponent) {
515
+ // Assign values without declaration.
516
+ // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration
517
+ ({
518
+ currencyCode
519
+ } = fareComponent.currency);
520
+ transitFare = fareComponent.cents;
521
+ }
522
+
523
+ return {
524
+ currencyCode,
525
+ transitFare
512
526
  };
513
527
  }
514
528
  //# sourceMappingURL=itinerary.js.map