@opentripplanner/core-utils 4.11.6-alpha.1 → 5.0.0

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 (70) hide show
  1. package/esm/deprecated-with-types.js +47 -0
  2. package/esm/deprecated-with-types.js.map +1 -0
  3. package/esm/index.js +0 -4
  4. package/esm/index.js.map +1 -1
  5. package/esm/itinerary.js +1 -1
  6. package/esm/itinerary.js.map +1 -1
  7. package/esm/map.js +4 -9
  8. package/esm/map.js.map +1 -1
  9. package/esm/route.js +5 -3
  10. package/esm/route.js.map +1 -1
  11. package/esm/storage.js +1 -0
  12. package/esm/storage.js.map +1 -1
  13. package/esm/time.js +6 -36
  14. package/esm/time.js.map +1 -1
  15. package/esm/ui.js +1 -1
  16. package/esm/ui.js.map +1 -1
  17. package/lib/deprecated-with-types.d.ts +23 -0
  18. package/lib/deprecated-with-types.d.ts.map +1 -0
  19. package/lib/deprecated-with-types.js +61 -0
  20. package/lib/deprecated-with-types.js.map +1 -0
  21. package/lib/index.d.ts +19 -0
  22. package/lib/index.d.ts.map +1 -0
  23. package/lib/index.js +0 -6
  24. package/lib/index.js.map +1 -1
  25. package/lib/itinerary.d.ts +113 -0
  26. package/lib/itinerary.d.ts.map +1 -0
  27. package/lib/itinerary.js +2 -1
  28. package/lib/itinerary.js.map +1 -1
  29. package/lib/map.d.ts +30 -0
  30. package/lib/map.d.ts.map +1 -0
  31. package/lib/map.js +3 -8
  32. package/lib/map.js.map +1 -1
  33. package/lib/route.d.ts +98 -0
  34. package/lib/route.d.ts.map +1 -0
  35. package/lib/route.js +5 -3
  36. package/lib/route.js.map +1 -1
  37. package/lib/storage.d.ts +19 -0
  38. package/lib/storage.d.ts.map +1 -0
  39. package/lib/storage.js +2 -0
  40. package/lib/storage.js.map +1 -1
  41. package/lib/time.d.ts +65 -0
  42. package/lib/time.d.ts.map +1 -0
  43. package/lib/time.js +22 -39
  44. package/lib/time.js.map +1 -1
  45. package/lib/ui.d.ts +13 -0
  46. package/lib/ui.d.ts.map +1 -0
  47. package/lib/ui.js +1 -1
  48. package/lib/ui.js.map +1 -1
  49. package/package.json +4 -1
  50. package/src/__tests__/__snapshots__/route.js.snap +30 -30
  51. package/src/deprecated-with-types.ts +62 -0
  52. package/src/{index.js → index.ts} +0 -4
  53. package/src/{itinerary.js → itinerary.ts} +70 -36
  54. package/src/{map.js → map.ts} +43 -31
  55. package/src/{route.js → route.ts} +52 -28
  56. package/src/{storage.js → storage.ts} +6 -5
  57. package/src/{time.js → time.ts} +28 -46
  58. package/src/{ui.js → ui.ts} +8 -8
  59. package/tsconfig.json +15 -0
  60. package/tsconfig.tsbuildinfo +4921 -0
  61. package/esm/messages.js +0 -25
  62. package/esm/messages.js.map +0 -1
  63. package/esm/types.js +0 -560
  64. package/esm/types.js.map +0 -1
  65. package/lib/messages.js +0 -29
  66. package/lib/messages.js.map +0 -1
  67. package/lib/types.js +0 -661
  68. package/lib/types.js.map +0 -1
  69. package/src/messages.js +0 -20
  70. package/src/types.js +0 -605
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,SAAS,EACT,WAAW,EACX,GAAG,EACH,QAAQ,EACR,cAAc,EACd,YAAY,EACb,MAAM,wBAAwB,CAAC;AAShC,OAAO,EACL,cAAc,EACd,aAAa,EACb,cAAc,EAEf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AAEzD,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,YAAY,GAC5B,QAAQ,CAYV;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,QAAQ,CAKX;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,QAAQ,EAClB,WAAW,UAAO,GACjB,MAAM,CAcR;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,GAAG,OAAO,CAG7E;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,OAAO,EAAE,EACpB,aAAa,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,EACnC,cAAc,EAAE,OAAO,GACtB,cAAc,CA+NhB;AAED,aAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AACF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAErE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAEpE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAEtE;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAOvD"}
package/lib/map.js CHANGED
@@ -125,14 +125,8 @@ function itineraryToTransitive(itin, companies, getRouteLabel, disableFlexArc) {
125
125
  if ((0, _itinerary.isAccessMode)(leg.mode)) {
126
126
  let fromPlaceId;
127
127
 
128
- if (leg.from.bikeShareId && (leg.mode === "BICYCLE" || leg.mode === "BICYCLE_RENT")) {
129
- fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;
130
-
131
- if ( // OTP2 Scooter case
132
- leg.mode === "SCOOTER") {
133
- fromPlaceId = `escooter_rent_station_${leg.from.name}`;
134
- } // OTP1 Scooter case
135
-
128
+ if (leg.from.bikeShareId) {
129
+ fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`; // TODO: does this need to change to be OTP2 compatible?
136
130
  } else if (leg.from.vertexType === "VEHICLERENTAL") {
137
131
  fromPlaceId = `escooter_rent_station_${leg.from.name}`;
138
132
  } else if (leg.mode === "CAR" && idx > 0 && itin.legs[idx - 1].mode === "WALK") {
@@ -156,6 +150,7 @@ function itineraryToTransitive(itin, companies, getRouteLabel, disableFlexArc) {
156
150
  }
157
151
 
158
152
  const segment = {
153
+ arc: false,
159
154
  type: leg.mode,
160
155
  streetEdges: [streetEdgeId],
161
156
  from: {
package/lib/map.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/map.js"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","stringToCoords","str","split","map","c","constructLocation","latlng","lng","formatStoredPlaceName","location","withDetails","displayName","type","name","detailText","matchLatLon","location1","location2","itineraryToTransitive","itin","companies","getRouteLabel","disableFlexArc","tdata","journeys","streetEdges","places","patterns","routes","stops","streetEdgeId","patternId","journey","journey_id","journey_name","segments","push","place_id","place_lat","legs","from","place_lon","length","to","forEach","leg","idx","mode","fromPlaceId","bikeShareId","vertexType","toPlaceId","segment","hailedCar","arc","edge_id","geometry","legGeometry","place_name","stopId","hasInterStopGeometry","interStopGeometry","hasLegGeometry","points","hasIntermediateStopGeometry","intermediateStops","ptnId","pattern","pattern_id","pattern_name","route_id","routeId","stop_id","stop_name","stop_lat","stop_lon","stop","i","routeLabel","routeShortName","agency_id","agencyId","route_short_name","route_long_name","routeLongName","route_type","routeType","route_color","routeColor","from_stop_index","to_stop_index","Object","values","isBikeshareStation","place","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAQA;;AASO,SAASA,yBAAT,CAAmCC,eAAnC,EAAoD;AACzD,MAAIA,eAAe,CAACC,KAAhB,IAAyB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CAAhE;AACD;;AAEM,SAASE,mBAAT,CAA6BH,KAA7B,EAAoC;AACzC,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,WAA3B,MAA4C,CAAC,CAApD;AACD;;AAEM,SAASG,UAAT,CAAoBvG,GAApB,EAAyB;AAC9B,SAAOwG,MAAM,CAACC,QAAP,CAAgBzG,GAAhB,KAAwBA,GAAG,IAAI,CAAC,EAAhC,IAAsCA,GAAG,IAAI,EAApD;AACD;;AAEM,SAAS0G,UAAT,CAAoB9F,GAApB,EAAyB;AAC9B,SAAO4F,MAAM,CAACC,QAAP,CAAgB7F,GAAhB,KAAwBA,GAAG,IAAI,CAAC,GAAhC,IAAuCA,GAAG,IAAI,GAArD;AACD;;AAEM,SAAS+F,aAAT,CAAuBC,GAAvB,EAA4B;AACjC,SACEC,KAAK,CAACC,OAAN,CAAcF,GAAd,KACAA,GAAG,CAAC7D,MAAJ,KAAe,CADf,IAEAwD,UAAU,CAACK,GAAG,CAAC,CAAD,CAAJ,CAFV,IAGAF,UAAU,CAACE,GAAG,CAAC,CAAD,CAAJ,CAJZ;AAMD","sourcesContent":["import {\n getPlaceName,\n isTransit,\n isFlex,\n toSentenceCase,\n isAccessMode\n} from \"./itinerary\";\n\nimport {\n coordsToString,\n getDetailText,\n latlngToString,\n logDeprecationWarning\n} from \"./deprecated\";\n\nexport { coordsToString, getDetailText, latlngToString };\n\nexport function currentPositionToLocation(currentPosition) {\n if (currentPosition.error || !currentPosition.coords) {\n console.warn(\n \"Cannot construct location from current position due to geolocation error or missing coordinates.\"\n );\n return null;\n }\n return {\n lat: currentPosition.coords.latitude,\n lon: currentPosition.coords.longitude,\n category: \"CURRENT_LOCATION\"\n };\n}\n\nexport function stringToCoords(str) {\n return (str && str.split(\",\").map(c => +c)) || [];\n}\n\nexport function constructLocation(latlng) {\n return {\n lat: latlng.lat,\n lon: latlng.lng\n };\n}\n\nexport function formatStoredPlaceName(location, withDetails = true) {\n if (withDetails) {\n logDeprecationWarning(\"the formatStoredPlaceName withDetails parameter\");\n }\n\n let displayName =\n location.type === \"home\" || location.type === \"work\"\n ? toSentenceCase(location.type)\n : location.name;\n if (withDetails) {\n const detailText = getDetailText(location);\n if (detailText) displayName += ` (${detailText})`;\n }\n return displayName;\n}\n\nexport function matchLatLon(location1, location2) {\n if (!location1 || !location2) return location1 === location2;\n return location1.lat === location2.lat && location1.lon === location2.lon;\n}\n\n/**\n * Converts an OTP itinerary object to a transtive.js itinerary object.\n * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.\n * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.\n * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)\n * and returns a string representing the route label to display for that leg.\n * @returns An itinerary in the transitive.js format.\n */\nexport function itineraryToTransitive(\n itin,\n companies,\n getRouteLabel,\n disableFlexArc\n) {\n const tdata = {\n journeys: [],\n streetEdges: [],\n places: [],\n patterns: [],\n routes: [],\n stops: []\n };\n const routes = {};\n const stops = {};\n let streetEdgeId = 0;\n let patternId = 0;\n\n const journey = {\n journey_id: \"itin\",\n // This string is not shown in the UI\n journey_name: \"Iterarary-derived Journey\",\n segments: []\n };\n\n // add 'from' and 'to' places to the tdata places array\n tdata.places.push({\n place_id: \"from\",\n place_lat: itin.legs[0].from.lat,\n place_lon: itin.legs[0].from.lon\n });\n tdata.places.push({\n place_id: \"to\",\n place_lat: itin.legs[itin.legs.length - 1].to.lat,\n place_lon: itin.legs[itin.legs.length - 1].to.lon\n });\n\n itin.legs.forEach((leg, idx) => {\n if (isAccessMode(leg.mode)) {\n let fromPlaceId;\n if (\n leg.from.bikeShareId &&\n (leg.mode === \"BICYCLE\" || leg.mode === \"BICYCLE_RENT\")\n ) {\n fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;\n if (\n // OTP2 Scooter case\n leg.mode === \"SCOOTER\"\n ) {\n fromPlaceId = `escooter_rent_station_${leg.from.name}`;\n }\n // OTP1 Scooter case\n } else if (leg.from.vertexType === \"VEHICLERENTAL\") {\n fromPlaceId = `escooter_rent_station_${leg.from.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx > 0 &&\n itin.legs[idx - 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs preceded by walking legs\n fromPlaceId = `itin_car_${streetEdgeId}_from`;\n } else {\n fromPlaceId = `itin_street_${streetEdgeId}_from`;\n }\n\n let toPlaceId;\n if (leg.to.bikeShareId) {\n toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`;\n } else if (leg.to.vertexType === \"VEHICLERENTAL\") {\n toPlaceId = `escooter_rent_station_${leg.to.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx < itin.legs.length - 1 &&\n itin.legs[idx + 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs followed by walking legs\n toPlaceId = `itin_car_${streetEdgeId}_to`;\n } else {\n toPlaceId = `itin_street_${streetEdgeId}_to`;\n }\n\n const segment = {\n type: leg.mode,\n streetEdges: [streetEdgeId],\n from: { type: \"PLACE\", place_id: fromPlaceId },\n to: { type: \"PLACE\", place_id: toPlaceId }\n };\n // For TNC segments, draw using an arc\n if (leg.mode === \"CAR\" && leg.hailedCar) segment.arc = true;\n journey.segments.push(segment);\n\n tdata.streetEdges.push({\n edge_id: streetEdgeId,\n geometry: leg.legGeometry\n });\n tdata.places.push({\n place_id: fromPlaceId,\n // Do not label the from place in addition to the to place. Otherwise,\n // in some cases (bike rental station) the label for a single place will\n // appear twice on the rendered transitive view.\n // See https://github.com/conveyal/trimet-mod-otp/issues/152\n // place_name: leg.from.name,\n place_lat: leg.from.lat,\n place_lon: leg.from.lon\n });\n tdata.places.push({\n place_id: toPlaceId,\n // This string is not shown in the UI\n place_name: getPlaceName(leg.to, companies),\n place_lat: leg.to.lat,\n place_lon: leg.to.lon\n });\n streetEdgeId++;\n }\n\n if (isTransit(leg.mode)) {\n // Flex routes sometimes have the same from and to IDs, but\n // these stops still need to be rendered separately!\n if (leg.from.stopId === leg.to.stopId) {\n leg.to.stopId = `${leg.to.stopId}_flexed_to`;\n }\n // determine if we have valid inter-stop geometry\n const hasInterStopGeometry = !!leg.interStopGeometry;\n const hasLegGeometry = !!leg.legGeometry?.points;\n const hasIntermediateStopGeometry =\n hasInterStopGeometry &&\n leg.intermediateStops &&\n leg.interStopGeometry.length === leg.intermediateStops.length + 1;\n\n // create leg-specific pattern\n const ptnId = `ptn_${patternId}`;\n const pattern = {\n pattern_id: ptnId,\n // This string is not shown in the UI\n pattern_name: `Pattern ${patternId}`,\n route_id: leg.routeId,\n stops: []\n };\n\n // add 'from' stop to stops dictionary and pattern object\n stops[leg.from.stopId] = {\n stop_id: leg.from.stopId,\n stop_name: leg.from.name,\n stop_lat: leg.from.lat,\n stop_lon: leg.from.lon\n };\n pattern.stops.push({ stop_id: leg.from.stopId });\n\n // add intermediate stops to stops dictionary and pattern object\n // If there is no intermediateStopGeometry, do not add the intermediate stops\n // as it will be straight lines instead of the nice legGeometry (but only if\n // the legGeometry exists).\n if (\n leg.intermediateStops &&\n (hasIntermediateStopGeometry || !hasLegGeometry)\n ) {\n leg.intermediateStops.forEach((stop, i) => {\n stops[stop.stopId] = {\n stop_id: stop.stopId,\n stop_name: stop.name,\n stop_lat: stop.lat,\n stop_lon: stop.lon\n };\n pattern.stops.push({\n stop_id: stop.stopId,\n geometry:\n hasIntermediateStopGeometry && leg.interStopGeometry[i].points\n });\n });\n }\n\n // add 'to' stop to stops dictionary and pattern object\n stops[leg.to.stopId] = {\n stop_id: leg.to.stopId,\n stop_name: leg.to.name,\n stop_lat: leg.to.lat,\n stop_lon: leg.to.lon\n };\n pattern.stops.push({\n stop_id: leg.to.stopId,\n geometry:\n // Some legs don't have intermediateStopGeometry, but do have valid legGeometry\n (hasInterStopGeometry || hasLegGeometry) &&\n (hasIntermediateStopGeometry\n ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points\n : leg.legGeometry.points)\n });\n\n // add route to the route dictionary\n // with a custom route label if specified.\n const routeLabel =\n typeof getRouteLabel === \"function\"\n ? getRouteLabel(leg)\n : leg.routeShortName;\n routes[leg.routeId] = {\n agency_id: leg.agencyId,\n route_id: leg.routeId,\n route_short_name: routeLabel || \"\",\n route_long_name: leg.routeLongName || \"\",\n route_type: leg.routeType,\n route_color: leg.routeColor\n };\n\n // add the pattern to the tdata patterns array\n tdata.patterns.push(pattern);\n\n // add the pattern reference to the journey object\n journey.segments.push({\n arc:\n typeof disableFlexArc === \"undefined\" ? isFlex(leg) : !disableFlexArc,\n type: \"TRANSIT\",\n patterns: [\n {\n pattern_id: ptnId,\n from_stop_index: 0,\n to_stop_index: hasIntermediateStopGeometry\n ? leg.intermediateStops.length + 2 - 1\n : 1\n }\n ]\n });\n\n patternId++;\n }\n });\n\n // add the routes and stops to the tdata arrays\n tdata.routes.push(...Object.values(routes));\n tdata.stops.push(...Object.values(stops));\n\n // add the journey to the tdata journeys array\n tdata.journeys.push(journey);\n\n // console.log('derived tdata', tdata);\n return tdata;\n}\n\nexport function isBikeshareStation(place) {\n return place.place_id.lastIndexOf(\"bicycle_rent_station\") !== -1;\n}\n\nexport function isEScooterStation(place) {\n return place.place_id.lastIndexOf(\"escooter_rent_station\") !== -1;\n}\n\nexport function isCarWalkTransition(place) {\n return place.place_id.lastIndexOf(\"itin_car_\") !== -1;\n}\n\nexport function isValidLat(lat) {\n return Number.isFinite(lat) && lat >= -90 && lat <= 90;\n}\n\nexport function isValidLng(lng) {\n return Number.isFinite(lng) && lng >= -180 && lng <= 180;\n}\n\nexport function isValidLatLng(arr) {\n return (\n Array.isArray(arr) &&\n arr.length === 2 &&\n isValidLat(arr[0]) &&\n isValidLng(arr[1])\n );\n}\n"],"file":"map.js"}
1
+ {"version":3,"sources":["../src/map.ts"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","stringToCoords","str","split","map","c","constructLocation","latlng","lng","formatStoredPlaceName","location","withDetails","displayName","type","name","detailText","matchLatLon","location1","location2","itineraryToTransitive","itin","companies","getRouteLabel","disableFlexArc","tdata","journeys","streetEdges","places","patterns","routes","stops","streetEdgeId","patternId","journey","journey_id","journey_name","segments","push","place_id","place_lat","legs","from","place_lon","length","to","forEach","leg","idx","mode","fromPlaceId","bikeShareId","vertexType","toPlaceId","segment","arc","hailedCar","edge_id","geometry","legGeometry","place_name","stopId","hasInterStopGeometry","interStopGeometry","hasLegGeometry","points","hasIntermediateStopGeometry","intermediateStops","ptnId","pattern","pattern_id","pattern_name","route_id","routeId","stop_id","stop_name","stop_lat","stop_lon","stop","i","routeLabel","routeShortName","agency_id","agencyId","route_short_name","route_long_name","routeLongName","route_type","routeType","route_color","routeColor","from_stop_index","to_stop_index","Object","values","isBikeshareStation","place","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;AAQA;;AASO,SAASA,yBAAT,CACLC,eADK,EAEK;AACV,MAAIA,eAAe,CAACC,KAAhB,IAAyB,CAACD,eAAe,CAACE,MAA9C,EAAsD;AACpDC,IAAAA,OAAO,CAACC,IAAR,CACE,kGADF;AAGA,WAAO,IAAP;AACD;;AACD,SAAO;AACLC,IAAAA,GAAG,EAAEL,eAAe,CAACE,MAAhB,CAAuBI,QADvB;AAELC,IAAAA,GAAG,EAAEP,eAAe,CAACE,MAAhB,CAAuBM,SAFvB;AAGLC,IAAAA,QAAQ,EAAE;AAHL,GAAP;AAKD;;AAEM,SAASC,cAAT,CAAwBC,GAAxB,EAA+C;AACpD,SAAQA,GAAG,IAAIA,GAAG,CAACC,KAAJ,CAAU,GAAV,EAAeC,GAAf,CAAmBC,CAAC,IAAI,CAACA,CAAzB,CAAR,IAAwC,EAA/C;AACD;;AAEM,SAASC,iBAAT,CAA2BC,MAA3B,EAGM;AACX,SAAO;AACLX,IAAAA,GAAG,EAAEW,MAAM,CAACX,GADP;AAELE,IAAAA,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Data,\n UserPosition\n} from \"@opentripplanner/types\";\nimport {\n getPlaceName,\n isAccessMode,\n isFlex,\n isTransit,\n toSentenceCase\n} from \"./itinerary\";\n\nimport {\n coordsToString,\n getDetailText,\n latlngToString,\n logDeprecationWarning\n} from \"./deprecated\";\n\nexport { coordsToString, getDetailText, latlngToString };\n\nexport function currentPositionToLocation(\n currentPosition: UserPosition\n): Location {\n if (currentPosition.error || !currentPosition.coords) {\n console.warn(\n \"Cannot construct location from current position due to geolocation error or missing coordinates.\"\n );\n return null;\n }\n return {\n lat: currentPosition.coords.latitude,\n lon: currentPosition.coords.longitude,\n category: \"CURRENT_LOCATION\"\n };\n}\n\nexport function stringToCoords(str: string): number[] {\n return (str && str.split(\",\").map(c => +c)) || [];\n}\n\nexport function constructLocation(latlng: {\n lat: number;\n lng: number;\n}): Location {\n return {\n lat: latlng.lat,\n lon: latlng.lng\n };\n}\n\nexport function formatStoredPlaceName(\n location: Location,\n withDetails = true\n): string {\n if (withDetails) {\n logDeprecationWarning(\"the formatStoredPlaceName withDetails parameter\");\n }\n\n let displayName =\n location.type === \"home\" || location.type === \"work\"\n ? toSentenceCase(location.type)\n : location.name;\n if (withDetails) {\n const detailText = getDetailText(location);\n if (detailText) displayName += ` (${detailText})`;\n }\n return displayName;\n}\n\nexport function matchLatLon(location1: Location, location2: Location): boolean {\n if (!location1 || !location2) return location1 === location2;\n return location1.lat === location2.lat && location1.lon === location2.lon;\n}\n\n/**\n * Converts an OTP itinerary object to a transtive.js itinerary object.\n * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.\n * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.\n * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)\n * and returns a string representing the route label to display for that leg.\n * @returns An itinerary in the transitive.js format.\n */\nexport function itineraryToTransitive(\n itin: Itinerary,\n companies: Company[],\n getRouteLabel: (leg: Leg) => string,\n disableFlexArc: boolean\n): TransitiveData {\n const tdata = {\n journeys: [],\n streetEdges: [],\n places: [],\n patterns: [],\n routes: [],\n stops: []\n };\n const routes = {};\n const stops = {};\n let streetEdgeId = 0;\n let patternId = 0;\n\n const journey = {\n journey_id: \"itin\",\n // This string is not shown in the UI\n journey_name: \"Iterarary-derived Journey\",\n segments: []\n };\n\n // add 'from' and 'to' places to the tdata places array\n tdata.places.push({\n place_id: \"from\",\n place_lat: itin.legs[0].from.lat,\n place_lon: itin.legs[0].from.lon\n });\n tdata.places.push({\n place_id: \"to\",\n place_lat: itin.legs[itin.legs.length - 1].to.lat,\n place_lon: itin.legs[itin.legs.length - 1].to.lon\n });\n\n itin.legs.forEach((leg, idx) => {\n if (isAccessMode(leg.mode)) {\n let fromPlaceId: string;\n if (leg.from.bikeShareId) {\n fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;\n // TODO: does this need to change to be OTP2 compatible?\n } else if (leg.from.vertexType === \"VEHICLERENTAL\") {\n fromPlaceId = `escooter_rent_station_${leg.from.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx > 0 &&\n itin.legs[idx - 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs preceded by walking legs\n fromPlaceId = `itin_car_${streetEdgeId}_from`;\n } else {\n fromPlaceId = `itin_street_${streetEdgeId}_from`;\n }\n\n let toPlaceId;\n if (leg.to.bikeShareId) {\n toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`;\n } else if (leg.to.vertexType === \"VEHICLERENTAL\") {\n toPlaceId = `escooter_rent_station_${leg.to.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx < itin.legs.length - 1 &&\n itin.legs[idx + 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs followed by walking legs\n toPlaceId = `itin_car_${streetEdgeId}_to`;\n } else {\n toPlaceId = `itin_street_${streetEdgeId}_to`;\n }\n\n const segment = {\n arc: false,\n type: leg.mode,\n streetEdges: [streetEdgeId],\n from: { type: \"PLACE\", place_id: fromPlaceId },\n to: { type: \"PLACE\", place_id: toPlaceId }\n };\n // For TNC segments, draw using an arc\n if (leg.mode === \"CAR\" && leg.hailedCar) segment.arc = true;\n journey.segments.push(segment);\n\n tdata.streetEdges.push({\n edge_id: streetEdgeId,\n geometry: leg.legGeometry\n });\n tdata.places.push({\n place_id: fromPlaceId,\n // Do not label the from place in addition to the to place. Otherwise,\n // in some cases (bike rental station) the label for a single place will\n // appear twice on the rendered transitive view.\n // See https://github.com/conveyal/trimet-mod-otp/issues/152\n // place_name: leg.from.name,\n place_lat: leg.from.lat,\n place_lon: leg.from.lon\n });\n tdata.places.push({\n place_id: toPlaceId,\n // This string is not shown in the UI\n place_name: getPlaceName(leg.to, companies),\n place_lat: leg.to.lat,\n place_lon: leg.to.lon\n });\n streetEdgeId++;\n }\n\n if (isTransit(leg.mode)) {\n // Flex routes sometimes have the same from and to IDs, but\n // these stops still need to be rendered separately!\n if (leg.from.stopId === leg.to.stopId) {\n leg.to.stopId = `${leg.to.stopId}_flexed_to`;\n }\n // determine if we have valid inter-stop geometry\n const hasInterStopGeometry = !!leg.interStopGeometry;\n const hasLegGeometry = !!leg.legGeometry?.points;\n const hasIntermediateStopGeometry =\n hasInterStopGeometry &&\n leg.intermediateStops &&\n leg.interStopGeometry.length === leg.intermediateStops.length + 1;\n\n // create leg-specific pattern\n const ptnId = `ptn_${patternId}`;\n const pattern = {\n pattern_id: ptnId,\n // This string is not shown in the UI\n pattern_name: `Pattern ${patternId}`,\n route_id: leg.routeId,\n stops: []\n };\n\n // add 'from' stop to stops dictionary and pattern object\n stops[leg.from.stopId] = {\n stop_id: leg.from.stopId,\n stop_name: leg.from.name,\n stop_lat: leg.from.lat,\n stop_lon: leg.from.lon\n };\n pattern.stops.push({ stop_id: leg.from.stopId });\n\n // add intermediate stops to stops dictionary and pattern object\n // If there is no intermediateStopGeometry, do not add the intermediate stops\n // as it will be straight lines instead of the nice legGeometry (but only if\n // the legGeometry exists).\n if (\n leg.intermediateStops &&\n (hasIntermediateStopGeometry || !hasLegGeometry)\n ) {\n leg.intermediateStops.forEach((stop, i) => {\n stops[stop.stopId] = {\n stop_id: stop.stopId,\n stop_name: stop.name,\n stop_lat: stop.lat,\n stop_lon: stop.lon\n };\n pattern.stops.push({\n stop_id: stop.stopId,\n geometry:\n hasIntermediateStopGeometry && leg.interStopGeometry[i].points\n });\n });\n }\n\n // add 'to' stop to stops dictionary and pattern object\n stops[leg.to.stopId] = {\n stop_id: leg.to.stopId,\n stop_name: leg.to.name,\n stop_lat: leg.to.lat,\n stop_lon: leg.to.lon\n };\n pattern.stops.push({\n stop_id: leg.to.stopId,\n geometry:\n // Some legs don't have intermediateStopGeometry, but do have valid legGeometry\n (hasInterStopGeometry || hasLegGeometry) &&\n (hasIntermediateStopGeometry\n ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points\n : leg.legGeometry.points)\n });\n\n // add route to the route dictionary\n // with a custom route label if specified.\n const routeLabel =\n typeof getRouteLabel === \"function\"\n ? getRouteLabel(leg)\n : leg.routeShortName;\n routes[leg.routeId] = {\n agency_id: leg.agencyId,\n route_id: leg.routeId,\n route_short_name: routeLabel || \"\",\n route_long_name: leg.routeLongName || \"\",\n route_type: leg.routeType,\n route_color: leg.routeColor\n };\n\n // add the pattern to the tdata patterns array\n tdata.patterns.push(pattern);\n\n // add the pattern reference to the journey object\n journey.segments.push({\n arc:\n typeof disableFlexArc === \"undefined\" ? isFlex(leg) : !disableFlexArc,\n type: \"TRANSIT\",\n patterns: [\n {\n pattern_id: ptnId,\n from_stop_index: 0,\n to_stop_index: hasIntermediateStopGeometry\n ? leg.intermediateStops.length + 2 - 1\n : 1\n }\n ]\n });\n\n patternId++;\n }\n });\n\n // add the routes and stops to the tdata arrays\n tdata.routes.push(...Object.values(routes));\n tdata.stops.push(...Object.values(stops));\n\n // add the journey to the tdata journeys array\n tdata.journeys.push(journey);\n\n // console.log('derived tdata', tdata);\n return tdata;\n}\n\ntype TransitivePlaceRaw = {\n place_id: string;\n};\nexport function isBikeshareStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"bicycle_rent_station\") !== -1;\n}\n\nexport function isEScooterStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"escooter_rent_station\") !== -1;\n}\n\nexport function isCarWalkTransition(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"itin_car_\") !== -1;\n}\n\nexport function isValidLat(lat: number): boolean {\n return Number.isFinite(lat) && lat >= -90 && lat <= 90;\n}\n\nexport function isValidLng(lng: number): boolean {\n return Number.isFinite(lng) && lng >= -180 && lng <= 180;\n}\n\nexport function isValidLatLng(arr: LatLngArray): boolean {\n return (\n Array.isArray(arr) &&\n arr.length === 2 &&\n isValidLat(arr[0]) &&\n isValidLng(arr[1])\n );\n}\n"],"file":"map.js"}
package/lib/route.d.ts ADDED
@@ -0,0 +1,98 @@
1
+ import { Leg, Route, TransitOperator } from "@opentripplanner/types";
2
+ /**
3
+ * Returns the transit operator (if an exact match is found) from the transit
4
+ * operators config value. It is critical to use both the feedId and agencyId in
5
+ * this method because it is possible in OTP for there to be a duplicate
6
+ * agencyId in separate feeds.
7
+ *
8
+ * @param {string} feedId The feedId that this transit agency belongs to
9
+ * @param {string} agencyId The agencyId of the transit agency
10
+ * @param {array} transitOperators The transitOperators list from the config
11
+ * @return {object} The transitOperator if a match was found or null if no match
12
+ * was found
13
+ */
14
+ export declare function getTransitOperatorFromFeedIdAndAgencyId(feedId: string, agencyId: string | number, transitOperators: TransitOperator[]): TransitOperator;
15
+ /**
16
+ * Looks up an operator from the provided leg.
17
+ *
18
+ * @param {object} leg The Itinerary Leg from which to find the transit
19
+ * operator
20
+ * @param {object} transitOperators transitOperators from config.
21
+ * @return {object} the operator if one was found or null if no match was found
22
+ */
23
+ export declare function getTransitOperatorFromLeg(leg: Leg, transitOperators: TransitOperator[]): TransitOperator;
24
+ /**
25
+ * Looks up an operator from the provided configuration given an OTP route.
26
+ * NOTE: this assumes the use of the OTP Route model or a modified OTP
27
+ * RouteShort model (such as the one found in the IBI fork of OTP) that also
28
+ * returns the agencyId.
29
+ *
30
+ * @param {object} route Either an OTP Route or RouteShort model
31
+ * @param {array} transitOperators transitOperators from config
32
+ * @return {object} the operator if one was found or null if no match was found
33
+ */
34
+ export declare function getTransitOperatorFromOtpRoute(route: Route, transitOperators: TransitOperator[]): TransitOperator;
35
+ /**
36
+ * Checks whether an appropriate comparison of numeric values can be made for
37
+ * sorting purposes. If both values are not valid numbers according to the
38
+ * isNaN check, then this function returns undefined which indicates that a
39
+ * secondary sorting criteria should be used instead. If one value is valid and
40
+ * the other is not, then the valid value will be given sorting priority. If
41
+ * both values are valid numbers, the difference is obtained as the sort value.
42
+ *
43
+ * An optional argument can be provided which will be used to obtain the
44
+ * comparison value from the comparison function arguments.
45
+ *
46
+ * IMPORTANT: the comparison values must be numeric values or at least be
47
+ * attempted to be converted to numeric values! If one of the arguments is
48
+ * something crazy like an empty string, unexpected behavior will occur because
49
+ * JavaScript.
50
+ *
51
+ * @param {function} [objGetterFn] An optional function to obtain the
52
+ * comparison value from the comparator function arguments
53
+ */
54
+ export declare function makeNumericValueComparator(objGetterFn?: (item: Route) => number): (a: number, b: number) => number;
55
+ /**
56
+ * Create a comparator function that compares string values. The comparison
57
+ * values feed to the sort comparator function are assumed to be objects that
58
+ * will have either undefined, null or string values at the given key. If one
59
+ * object has undefined, null or an empty string, but the other does have a
60
+ * string with length > 0, then that string will get priority.
61
+ *
62
+ * @param {function} [objGetterFn] An optional function to obtain the
63
+ * comparison value from the comparator function arguments
64
+ */
65
+ export declare function makeStringValueComparator(objGetterFn?: (item: Route) => string): (a: string, b: string) => number;
66
+ /**
67
+ * Creates a sort comparator function to compares routes for the purposes of
68
+ * sorting and displaying in a user interface. This takes in a single optional
69
+ * argument which should be a list of transitOperators as defined in the config
70
+ * file. Due to GTFS feeds having varying levels of data quality, a multi-
71
+ * criteria sort is needed to account for various differences. The criteria
72
+ * included here are each applied to the routes in the order listed. If a given
73
+ * sort criterion yields equivalence (e.g., two routes have the short name
74
+ * "20"), the comparator falls back onto the next sort criterion (e.g., long
75
+ * name). The sort operates on the following values (in order):
76
+ *
77
+ * 1. Transit Operator. The transit operator will be attempted to be obtained
78
+ * for each route. If no argument is provided when creating this comparator
79
+ * function, then routes will be sorted by their agency's name. If an
80
+ * argument is provided and a match is found based off of the route's feed_id
81
+ * and agency_id and a transitOperator's feed_id and agency_id, then the
82
+ * field transitOperator.order will be used as the comparator value as long
83
+ * as it is numeric. If it is not numeric, a value is returned indicating
84
+ * that this transit operator should be placed at the end of the list.
85
+ * 2. sortOrder. Routes that do not have a valid sortOrder will be placed
86
+ * beneath those that do.
87
+ * 3. route type (OTP mode). See routeTypeComparator code for prioritization of
88
+ * route types.
89
+ * 4. shortNames that begin with alphabetic characters. shortNames that do not
90
+ * start with alphabetic characters will be place beneath those that do.
91
+ * 5. shortName as integer. shortNames that cannot be parsed as integers will
92
+ * be placed beneath those that are valid.
93
+ * 6. shortName as string. Routes without shortNames will be placed beneath
94
+ * those with shortNames.
95
+ * 7. longName as string.
96
+ */
97
+ export declare function makeRouteComparator(transitOperators: TransitOperator[]): (a: number, b: number) => number;
98
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACrE;;;;;;;;;;;GAWG;AACH,wBAAgB,uCAAuC,CACrD,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,gBAAgB,EAAE,eAAe,EAAE,GAClC,eAAe,CAQjB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,GAAG,EACR,gBAAgB,EAAE,eAAe,EAAE,GAClC,eAAe,CAQjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,KAAK,EACZ,gBAAgB,EAAE,eAAe,EAAE,GAClC,eAAe,CAkBjB;AA0MD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,OAI1B,MAAM,KAAK,MAAM,KAAG,MAAM,CAatC;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,OAE1B,MAAM,KAAK,MAAM,KAAG,MAAM,CAatC;AAqCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,eAAe,EAAE,GAClC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAUlC"}
package/lib/route.js CHANGED
@@ -132,7 +132,7 @@ function makeTransitOperatorComparator(transitOperators) {
132
132
  if (aVal < bVal) return -1;
133
133
  if (aVal > bVal) return 1;
134
134
  return 0;
135
- } // transitOperators are defined and therefore a numeric value is guaranteed
135
+ } // @ts-expect-error transitOperators are defined and therefore a numeric value is guaranteed
136
136
  // to be returned
137
137
 
138
138
 
@@ -210,7 +210,7 @@ function getRouteTypeComparatorValue(route) {
210
210
  // For some strange reason, the short route response in OTP returns the
211
211
  // string-based modes, but the long route response returns the
212
212
  // integer route type. This attempts to account for both of those cases.
213
- if (!route) throw new Error("Route is undefined.", route);
213
+ if (!route) throw new Error(`Route is undefined. ${route}`);
214
214
 
215
215
  if (typeof modeComparatorValue[route.mode] !== "undefined") {
216
216
  return modeComparatorValue[route.mode];
@@ -220,6 +220,7 @@ function getRouteTypeComparatorValue(route) {
220
220
  return routeTypeComparatorValue[route.type];
221
221
  } // Default the comparator value to a large number (placing the route at the
222
222
  // end of the list).
223
+ // eslint-disable-next-line no-console
223
224
 
224
225
 
225
226
  console.warn("no mode/route type found for route", route);
@@ -301,7 +302,8 @@ function makeNumericValueComparator(objGetterFn) {
301
302
  const {
302
303
  aVal,
303
304
  bVal
304
- } = getSortValues(objGetterFn, a, b); // if both values aren't valid numbers, use the next sort criteria
305
+ } = getSortValues(objGetterFn, a, b);
306
+ if (typeof aVal !== "number" || typeof bVal !== "number") return 0; // if both values aren't valid numbers, use the next sort criteria
305
307
 
306
308
  if (isNaN(aVal) && isNaN(bVal)) return 0; // b is a valid number, b gets priority
307
309
 
package/lib/route.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/route.js"],"names":["getTransitOperatorFromFeedIdAndAgencyId","feedId","agencyId","transitOperators","find","transitOperator","getTransitOperatorFromLeg","leg","routeId","split","getTransitOperatorFromOtpRoute","route","id","agency","END_OF_LIST_COMPARATOR_VALUE","getTransitOperatorComparatorValue","length","name","agencyName","order","makeTransitOperatorComparator","a","b","aVal","bVal","getSortValues","getterFn","modeComparatorValue","SUBWAY","TRAM","RAIL","GONDOLA","FERRY","CABLE_CAR","FUNICULAR","BUS","routeTypeComparatorValue","getRouteTypeComparatorValue","Error","mode","type","console","warn","routeTypeComparator","startsWithAlphabeticCharacter","val","firstCharCode","charCodeAt","alphabeticShortNameComparator","aStartsWithAlphabeticCharacter","shortName","bStartsWithAlphabeticCharacter","makeNumericValueComparator","objGetterFn","isNaN","makeStringValueComparator","getRouteSortOrderValue","undefined","makeMultiCriteriaSort","criteria","i","curCriteriaComparatorValue","makeRouteComparator","obj","sortOrder","parseInt","longName"],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uCAAT,CACLC,MADK,EAELC,QAFK,EAGLC,gBAHK,EAIL;AACA,SACEA,gBAAgB,CAACC,IAAjB,CACEC,eAAe,IACbA,eAAe,CAACJ,MAAhB,KAA2BA,MAA3B,IACAI,eAAe,CAACH,QAAhB,KAA6BA,QAHjC,KAIK,IALP;AAOD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;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AAIA,GAAG,CAACG,QAAZ,CAPC,CAA5B;AASD","sourcesContent":["/**\n * Returns the transit operator (if an exact match is found) from the transit\n * operators config value. It is critical to use both the feedId and agencyId in\n * this method because it is possible in OTP for there to be a duplicate\n * agencyId in separate feeds.\n *\n * @param {string} feedId The feedId that this transit agency belongs to\n * @param {string} agencyId The agencyId of the transit agency\n * @param {array} transitOperators The transitOperators list from the config\n * @return {object} The transitOperator if a match was found or null if no match\n * was found\n */\nexport function getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n) {\n return (\n transitOperators.find(\n transitOperator =>\n transitOperator.feedId === feedId &&\n transitOperator.agencyId === agencyId\n ) || null\n );\n}\n\n/**\n * Looks up an operator from the provided leg.\n *\n * @param {object} leg The Itinerary Leg from which to find the transit\n * operator\n * @param {object} transitOperators transitOperators from config.\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromLeg(leg, transitOperators) {\n if (!leg.routeId || !leg.agencyId) return null;\n const feedId = leg.routeId.split(\":\")[0];\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n leg.agencyId,\n transitOperators\n );\n}\n\n/**\n * Looks up an operator from the provided configuration given an OTP route.\n * NOTE: this assumes the use of the OTP Route model or a modified OTP\n * RouteShort model (such as the one found in the IBI fork of OTP) that also\n * returns the agencyId.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromOtpRoute(route, transitOperators) {\n if (!route.id) return null;\n const feedId = route.id.split(\":\")[0];\n let agencyId;\n if (route.agency) {\n // This is returned in the OTP Route model\n agencyId = route.agency.id;\n } else if (route.agencyId) {\n // This is returned in the OTP RouteShort model (such as in the IBI fork)\n agencyId = route.agencyId;\n } else {\n return null;\n }\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n );\n}\n\n// The functions below are for enhanced route sorting functions for the route\n// viewer on OTP-react-redux.\n// They address route ordering issues discussed in\n// https://github.com/opentripplanner/otp-react-redux/pull/123 and\n// https://github.com/opentripplanner/otp-react-redux/pull/124.\n\n/**\n * A large comparator value that can safely be used in mathematical sort\n * comparisons to place things at the end of lists\n */\nconst END_OF_LIST_COMPARATOR_VALUE = 999999999999;\n\n/**\n * Returns a transit operator comparator value given a route and an optional\n * transitOperators config value. This function will do its best to handle all\n * kinds of input data as certain deployments of an implementing webapp may have\n * incomplete data and certain versions of OTP might not have a modified\n * implementation of the RouteShort model.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {mixed} this could return a string value (the route's agency name) if\n * the transitOperators value is not defined. Otherwise an integer will be\n * returned.\n */\nfunction getTransitOperatorComparatorValue(route, transitOperators) {\n // if the transitOperators is undefined or has zero length, use the route's\n // agency name as the comparator value\n if (!transitOperators || transitOperators.length === 0) {\n // OTP Route\n if (route.agency) return route.agency.name;\n // OTP RouteShort (base OTP repo or IBI fork)\n if (route.agencyName) return route.agencyName;\n // shouldn't happen as agency names will be defined\n return \"zzz\";\n }\n\n // find operator associated with route\n const transitOperator = getTransitOperatorFromOtpRoute(\n route,\n transitOperators\n );\n\n // if transit operator not found, return infinity\n if (!transitOperator) return END_OF_LIST_COMPARATOR_VALUE;\n\n // return the transit operator's sort value or END_OF_LIST_COMPARATOR_VALUE if\n // the sort value is not a number\n return typeof transitOperator.order === \"number\"\n ? transitOperator.order\n : END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of the\n * route's agency and provided transitOperators config data.\n */\nfunction makeTransitOperatorComparator(transitOperators) {\n return (a, b) => {\n const aVal = getTransitOperatorComparatorValue(a, transitOperators);\n const bVal = getTransitOperatorComparatorValue(b, transitOperators);\n if (typeof aVal === \"string\") {\n // happens when transitOperators is undefined. Both aVal are guaranteed to\n // be strings. Make a string comparison.\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n }\n\n // transitOperators are defined and therefore a numeric value is guaranteed\n // to be returned\n return aVal - bVal;\n };\n}\n\n/**\n * Gets the desired sort values according to an optional getter function. If the\n * getter function is not defined, the original sort values are returned.\n */\nfunction getSortValues(getterFn, a, b) {\n let aVal;\n let bVal;\n if (typeof getterFn === \"function\") {\n aVal = getterFn(a);\n bVal = getterFn(b);\n } else {\n aVal = a;\n bVal = b;\n }\n return { aVal, bVal };\n}\n\n// Lookup for the sort values associated with various OTP modes.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst modeComparatorValue = {\n SUBWAY: 1,\n TRAM: 2,\n RAIL: 3,\n GONDOLA: 4,\n FERRY: 5,\n CABLE_CAR: 6,\n FUNICULAR: 7,\n BUS: 8\n};\n\n// Lookup that maps route types to the OTP mode sort values.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst routeTypeComparatorValue = {\n 0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.\n 1: modeComparatorValue.SUBWAY, // - Subway, Metro.\n 2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.\n 3: modeComparatorValue.BUS, // - Bus.\n 4: modeComparatorValue.FERRY, // - Ferry.\n 5: modeComparatorValue.CABLE_CAR, // - Cable tram.\n 6: modeComparatorValue.GONDOLA, // - Gondola, etc.\n 7: modeComparatorValue.FUNICULAR, // - Funicular.\n // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just\n // associate them with bus/rail.\n 11: modeComparatorValue.BUS, // - Trolleybus.\n 12: modeComparatorValue.RAIL // - Monorail.\n};\n\n// Gets a comparator value for a given route's type (OTP mode).\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// ttps://github.com/documentationjs/documentation/issues/372\nfunction getRouteTypeComparatorValue(route) {\n // For some strange reason, the short route response in OTP returns the\n // string-based modes, but the long route response returns the\n // integer route type. This attempts to account for both of those cases.\n if (!route) throw new Error(\"Route is undefined.\", route);\n if (typeof modeComparatorValue[route.mode] !== \"undefined\") {\n return modeComparatorValue[route.mode];\n }\n if (typeof routeTypeComparatorValue[route.type] !== \"undefined\") {\n return routeTypeComparatorValue[route.type];\n }\n // Default the comparator value to a large number (placing the route at the\n // end of the list).\n console.warn(\"no mode/route type found for route\", route);\n return END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of route type\n * (OTP mode).\n */\nfunction routeTypeComparator(a, b) {\n return getRouteTypeComparatorValue(a) - getRouteTypeComparatorValue(b);\n}\n\n/**\n * Determines whether a value is a string that starts with an alphabetic\n * ascii character.\n */\nfunction startsWithAlphabeticCharacter(val) {\n if (typeof val === \"string\" && val.length > 0) {\n const firstCharCode = val.charCodeAt(0);\n return (\n (firstCharCode >= 65 && firstCharCode <= 90) ||\n (firstCharCode >= 97 && firstCharCode <= 122)\n );\n }\n return false;\n}\n\n/**\n * Sorts routes based off of whether the shortName begins with an alphabetic\n * character. Routes with shortn that do start with an alphabetic character will\n * be prioritized over those that don't.\n */\nfunction alphabeticShortNameComparator(a, b) {\n const aStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n a.shortName\n );\n const bStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n b.shortName\n );\n\n if (aStartsWithAlphabeticCharacter && bStartsWithAlphabeticCharacter) {\n // both start with an alphabetic character, return equivalence\n return 0;\n }\n // a does start with an alphabetic character, but b does not. Prioritize a\n if (aStartsWithAlphabeticCharacter) return -1;\n // b does start with an alphabetic character, but a does not. Prioritize b\n if (bStartsWithAlphabeticCharacter) return 1;\n // neither route has a shortName that starts with an alphabetic character.\n // Return equivalence\n return 0;\n}\n\n/**\n * Checks whether an appropriate comparison of numeric values can be made for\n * sorting purposes. If both values are not valid numbers according to the\n * isNaN check, then this function returns undefined which indicates that a\n * secondary sorting criteria should be used instead. If one value is valid and\n * the other is not, then the valid value will be given sorting priority. If\n * both values are valid numbers, the difference is obtained as the sort value.\n *\n * An optional argument can be provided which will be used to obtain the\n * comparison value from the comparison function arguments.\n *\n * IMPORTANT: the comparison values must be numeric values or at least be\n * attempted to be converted to numeric values! If one of the arguments is\n * something crazy like an empty string, unexpected behavior will occur because\n * JavaScript.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeNumericValueComparator(objGetterFn) {\n /* Note: Using the global version of isNaN (the Number version behaves differently. */\n /* eslint-disable no-restricted-globals */\n return (a, b) => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // if both values aren't valid numbers, use the next sort criteria\n if (isNaN(aVal) && isNaN(bVal)) return 0;\n // b is a valid number, b gets priority\n if (isNaN(aVal)) return 1;\n // a is a valid number, a gets priority\n if (isNaN(bVal)) return -1;\n // a and b are valid numbers, return the sort value\n return aVal - bVal;\n };\n}\n\n/**\n * Create a comparator function that compares string values. The comparison\n * values feed to the sort comparator function are assumed to be objects that\n * will have either undefined, null or string values at the given key. If one\n * object has undefined, null or an empty string, but the other does have a\n * string with length > 0, then that string will get priority.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeStringValueComparator(objGetterFn) {\n return (a, b) => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // both a and b are uncomparable strings, return equivalent value\n if (!aVal && !bVal) return 0;\n // a is not a comparable string, b gets priority\n if (!aVal) return 1;\n // b is not a comparable string, a gets priority\n if (!bVal) return -1;\n // a and b are comparable strings, return the sort value\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n };\n}\n\n/**\n * OpenTripPlanner sets the routeSortOrder to -999 by default. So, if that value\n * is encountered, assume that it actually means that the routeSortOrder is not\n * set in the GTFS.\n *\n * See https://github.com/opentripplanner/OpenTripPlanner/issues/2938\n * Also see https://github.com/opentripplanner/otp-react-redux/issues/122\n */\nfunction getRouteSortOrderValue(val) {\n return val === -999 ? undefined : val;\n}\n\n/**\n * Create a multi-criteria sort comparator function composed of other sort\n * comparator functions. Each comparator function will be ran in the order given\n * until a non-zero comparison value is obtained which is then immediately\n * returned. If all comparison functions return equivalence, then the values\n * are assumed to be equivalent.\n */\nfunction makeMultiCriteriaSort(...criteria) {\n return (a, b) => {\n for (let i = 0; i < criteria.length; i++) {\n const curCriteriaComparatorValue = criteria[i](a, b);\n // if the comparison objects are not equivalent, return the value obtained\n // in this current criteria comparison\n if (curCriteriaComparatorValue !== 0) {\n return curCriteriaComparatorValue;\n }\n }\n return 0;\n };\n}\n\n/**\n * Creates a sort comparator function to compares routes for the purposes of\n * sorting and displaying in a user interface. This takes in a single optional\n * argument which should be a list of transitOperators as defined in the config\n * file. Due to GTFS feeds having varying levels of data quality, a multi-\n * criteria sort is needed to account for various differences. The criteria\n * included here are each applied to the routes in the order listed. If a given\n * sort criterion yields equivalence (e.g., two routes have the short name\n * \"20\"), the comparator falls back onto the next sort criterion (e.g., long\n * name). The sort operates on the following values (in order):\n *\n * 1. Transit Operator. The transit operator will be attempted to be obtained\n * for each route. If no argument is provided when creating this comparator\n * function, then routes will be sorted by their agency's name. If an\n * argument is provided and a match is found based off of the route's feed_id\n * and agency_id and a transitOperator's feed_id and agency_id, then the\n * field transitOperator.order will be used as the comparator value as long\n * as it is numeric. If it is not numeric, a value is returned indicating\n * that this transit operator should be placed at the end of the list.\n * 2. sortOrder. Routes that do not have a valid sortOrder will be placed\n * beneath those that do.\n * 3. route type (OTP mode). See routeTypeComparator code for prioritization of\n * route types.\n * 4. shortNames that begin with alphabetic characters. shortNames that do not\n * start with alphabetic characters will be place beneath those that do.\n * 5. shortName as integer. shortNames that cannot be parsed as integers will\n * be placed beneath those that are valid.\n * 6. shortName as string. Routes without shortNames will be placed beneath\n * those with shortNames.\n * 7. longName as string.\n */\nexport function makeRouteComparator(transitOperators) {\n return makeMultiCriteriaSort(\n makeTransitOperatorComparator(transitOperators),\n makeNumericValueComparator(obj => getRouteSortOrderValue(obj.sortOrder)),\n routeTypeComparator,\n alphabeticShortNameComparator,\n makeNumericValueComparator(obj => parseInt(obj.shortName, 10)),\n makeStringValueComparator(obj => obj.shortName),\n makeStringValueComparator(obj => obj.longName)\n );\n}\n"],"file":"route.js"}
1
+ {"version":3,"sources":["../src/route.ts"],"names":["getTransitOperatorFromFeedIdAndAgencyId","feedId","agencyId","transitOperators","find","transitOperator","getTransitOperatorFromLeg","leg","routeId","split","getTransitOperatorFromOtpRoute","route","id","agency","END_OF_LIST_COMPARATOR_VALUE","getTransitOperatorComparatorValue","length","name","agencyName","order","makeTransitOperatorComparator","a","b","aVal","bVal","getSortValues","getterFn","modeComparatorValue","SUBWAY","TRAM","RAIL","GONDOLA","FERRY","CABLE_CAR","FUNICULAR","BUS","routeTypeComparatorValue","getRouteTypeComparatorValue","Error","mode","type","console","warn","routeTypeComparator","startsWithAlphabeticCharacter","val","firstCharCode","charCodeAt","alphabeticShortNameComparator","aStartsWithAlphabeticCharacter","shortName","bStartsWithAlphabeticCharacter","makeNumericValueComparator","objGetterFn","isNaN","makeStringValueComparator","getRouteSortOrderValue","undefined","makeMultiCriteriaSort","criteria","i","curCriteriaComparatorValue","makeRouteComparator","obj","sortOrder","parseInt","longName"],"mappings":";;;;;;;;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uCAAT,CACLC,MADK,EAELC,QAFK,EAGLC,gBAHK,EAIY;AACjB,SACEA,gBAAgB,CAACC,IAAjB,CACEC,eAAe,IACbA,eAAe,CAACJ,MAAhB,KAA2BA,MAA3B,IACAI,eAAe,CAACH,QAAhB,KAA6BA,QAHjC,KAIK,IALP;AAOD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,yBAAT,CACLC,GADK,EAELJ,gBAFK,EAGY;AACjB,MAAI,CAACI,GAAG,CAACC,OAAL,IAAgB,CAACD,GAAG,CAACL,QAAzB,EAAmC,OAAO,IAAP;AACnC,QAAMD,MAAM,GAAGM,GAAG,CAACC,OAAJ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AAT,CAAgCX,GAAhC,EAAqD;AACnD,SAAOA,GAAG,KAAK,CAAC,GAAT,GAAeY,SAAf,GAA2BZ,GAAlC;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASa,qBAAT,CACE,GAAGC,QADL,EAEE;AACA,SAAO,CAACtC,CAAD,EAAYC,CAAZ,KAAkC;AACvC,SAAK,IAAIsC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,QAAQ,CAAC3C,MAA7B,EAAqC4C,CAAC,EAAtC,EAA0C;AACxC,YAAMC,0BAA0B,GAAGF,QAAQ,CAACC,CAAD,CAAR,CAAYvC,CAAZ,EAAeC,CAAf,CAAnC,CADwC,CAExC;AACA;;AACA,UAAIuC,0BAA0B,KAAK,CAAnC,EAAsC;AACpC,eAAOA,0BAAP;AACD;AACF;;AACD,WAAO,CAAP;AACD,GAVD;AAWD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,CACL3D,gBADK,EAE6B;AAClC,SAAOuD,qBAAqB,CAC1BtC,6BAA6B,CAACjB,gBAAD,CADH,EAE1BiD,0BAA0B,CAACW,GAAG,IAAIP,sBAAsB,CAACO,GAAG,CAACC,SAAL,CAA9B,CAFA,EAG1BrB,mBAH0B,EAI1BK,6BAJ0B,EAK1BI,0BAA0B,CAACW,GAAG,IAAIE,QAAQ,CAACF,GAAG,CAACb,SAAL,EAAgB,EAAhB,CAAhB,CALA,EAM1BK,yBAAyB,CAACQ,GAAG,IAAIA,GAAG,CAACb,SAAZ,CANC,EAO1BK,yBAAyB,CAACQ,GAAG,IAAIA,GAAG,CAACG,QAAZ,CAPC,CAA5B;AASD","sourcesContent":["import { Leg, Route, TransitOperator } from \"@opentripplanner/types\";\n/**\n * Returns the transit operator (if an exact match is found) from the transit\n * operators config value. It is critical to use both the feedId and agencyId in\n * this method because it is possible in OTP for there to be a duplicate\n * agencyId in separate feeds.\n *\n * @param {string} feedId The feedId that this transit agency belongs to\n * @param {string} agencyId The agencyId of the transit agency\n * @param {array} transitOperators The transitOperators list from the config\n * @return {object} The transitOperator if a match was found or null if no match\n * was found\n */\nexport function getTransitOperatorFromFeedIdAndAgencyId(\n feedId: string,\n agencyId: string | number,\n transitOperators: TransitOperator[]\n): TransitOperator {\n return (\n transitOperators.find(\n transitOperator =>\n transitOperator.feedId === feedId &&\n transitOperator.agencyId === agencyId\n ) || null\n );\n}\n\n/**\n * Looks up an operator from the provided leg.\n *\n * @param {object} leg The Itinerary Leg from which to find the transit\n * operator\n * @param {object} transitOperators transitOperators from config.\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromLeg(\n leg: Leg,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!leg.routeId || !leg.agencyId) return null;\n const feedId = leg.routeId.split(\":\")[0];\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n leg.agencyId,\n transitOperators\n );\n}\n\n/**\n * Looks up an operator from the provided configuration given an OTP route.\n * NOTE: this assumes the use of the OTP Route model or a modified OTP\n * RouteShort model (such as the one found in the IBI fork of OTP) that also\n * returns the agencyId.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromOtpRoute(\n route: Route,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!route.id) return null;\n const feedId = route.id.split(\":\")[0];\n let agencyId: string | number;\n if (route.agency) {\n // This is returned in the OTP Route model\n agencyId = route.agency.id;\n } else if (route.agencyId) {\n // This is returned in the OTP RouteShort model (such as in the IBI fork)\n agencyId = route.agencyId;\n } else {\n return null;\n }\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n );\n}\n\n// The functions below are for enhanced route sorting functions for the route\n// viewer on OTP-react-redux.\n// They address route ordering issues discussed in\n// https://github.com/opentripplanner/otp-react-redux/pull/123 and\n// https://github.com/opentripplanner/otp-react-redux/pull/124.\n\n/**\n * A large comparator value that can safely be used in mathematical sort\n * comparisons to place things at the end of lists\n */\nconst END_OF_LIST_COMPARATOR_VALUE = 999999999999;\n\n/**\n * Returns a transit operator comparator value given a route and an optional\n * transitOperators config value. This function will do its best to handle all\n * kinds of input data as certain deployments of an implementing webapp may have\n * incomplete data and certain versions of OTP might not have a modified\n * implementation of the RouteShort model.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {mixed} this could return a string value (the route's agency name) if\n * the transitOperators value is not defined. Otherwise an integer will be\n * returned.\n */\nfunction getTransitOperatorComparatorValue(\n route: Route,\n transitOperators: TransitOperator[]\n): number | string {\n // if the transitOperators is undefined or has zero length, use the route's\n // agency name as the comparator value\n if (!transitOperators || transitOperators.length === 0) {\n // OTP Route\n if (route.agency) return route.agency.name;\n // OTP RouteShort (base OTP repo or IBI fork)\n if (route.agencyName) return route.agencyName;\n // shouldn't happen as agency names will be defined\n return \"zzz\";\n }\n\n // find operator associated with route\n const transitOperator = getTransitOperatorFromOtpRoute(\n route,\n transitOperators\n );\n\n // if transit operator not found, return infinity\n if (!transitOperator) return END_OF_LIST_COMPARATOR_VALUE;\n\n // return the transit operator's sort value or END_OF_LIST_COMPARATOR_VALUE if\n // the sort value is not a number\n return typeof transitOperator.order === \"number\"\n ? transitOperator.order\n : END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of the\n * route's agency and provided transitOperators config data.\n */\nfunction makeTransitOperatorComparator(transitOperators: TransitOperator[]) {\n return (a: Route, b: Route) => {\n const aVal = getTransitOperatorComparatorValue(a, transitOperators);\n const bVal = getTransitOperatorComparatorValue(b, transitOperators);\n if (typeof aVal === \"string\") {\n // happens when transitOperators is undefined. Both aVal are guaranteed to\n // be strings. Make a string comparison.\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n }\n // @ts-expect-error transitOperators are defined and therefore a numeric value is guaranteed\n // to be returned\n return aVal - bVal;\n };\n}\n\n/**\n * Gets the desired sort values according to an optional getter function. If the\n * getter function is not defined, the original sort values are returned.\n */\nfunction getSortValues(\n getterFn: (item: unknown) => unknown,\n a: unknown,\n b: unknown\n) {\n let aVal: unknown;\n let bVal: unknown;\n if (typeof getterFn === \"function\") {\n aVal = getterFn(a);\n bVal = getterFn(b);\n } else {\n aVal = a;\n bVal = b;\n }\n return { aVal, bVal };\n}\n\n// Lookup for the sort values associated with various OTP modes.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst modeComparatorValue = {\n SUBWAY: 1,\n TRAM: 2,\n RAIL: 3,\n GONDOLA: 4,\n FERRY: 5,\n CABLE_CAR: 6,\n FUNICULAR: 7,\n BUS: 8\n};\n\n// Lookup that maps route types to the OTP mode sort values.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst routeTypeComparatorValue = {\n 0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.\n 1: modeComparatorValue.SUBWAY, // - Subway, Metro.\n 2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.\n 3: modeComparatorValue.BUS, // - Bus.\n 4: modeComparatorValue.FERRY, // - Ferry.\n 5: modeComparatorValue.CABLE_CAR, // - Cable tram.\n 6: modeComparatorValue.GONDOLA, // - Gondola, etc.\n 7: modeComparatorValue.FUNICULAR, // - Funicular.\n // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just\n // associate them with bus/rail.\n 11: modeComparatorValue.BUS, // - Trolleybus.\n 12: modeComparatorValue.RAIL // - Monorail.\n};\n\n// Gets a comparator value for a given route's type (OTP mode).\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// ttps://github.com/documentationjs/documentation/issues/372\nfunction getRouteTypeComparatorValue(route: Route): number {\n // For some strange reason, the short route response in OTP returns the\n // string-based modes, but the long route response returns the\n // integer route type. This attempts to account for both of those cases.\n if (!route) throw new Error(`Route is undefined. ${route}`);\n if (typeof modeComparatorValue[route.mode] !== \"undefined\") {\n return modeComparatorValue[route.mode];\n }\n if (typeof routeTypeComparatorValue[route.type] !== \"undefined\") {\n return routeTypeComparatorValue[route.type];\n }\n // Default the comparator value to a large number (placing the route at the\n // end of the list).\n // eslint-disable-next-line no-console\n console.warn(\"no mode/route type found for route\", route);\n return END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of route type\n * (OTP mode).\n */\nfunction routeTypeComparator(a: Route, b: Route): number {\n return getRouteTypeComparatorValue(a) - getRouteTypeComparatorValue(b);\n}\n\n/**\n * Determines whether a value is a string that starts with an alphabetic\n * ascii character.\n */\nfunction startsWithAlphabeticCharacter(val: unknown): boolean {\n if (typeof val === \"string\" && val.length > 0) {\n const firstCharCode = val.charCodeAt(0);\n return (\n (firstCharCode >= 65 && firstCharCode <= 90) ||\n (firstCharCode >= 97 && firstCharCode <= 122)\n );\n }\n return false;\n}\n\n/**\n * Sorts routes based off of whether the shortName begins with an alphabetic\n * character. Routes with shortn that do start with an alphabetic character will\n * be prioritized over those that don't.\n */\nfunction alphabeticShortNameComparator(a: Route, b: Route): number {\n const aStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n a.shortName\n );\n const bStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n b.shortName\n );\n\n if (aStartsWithAlphabeticCharacter && bStartsWithAlphabeticCharacter) {\n // both start with an alphabetic character, return equivalence\n return 0;\n }\n // a does start with an alphabetic character, but b does not. Prioritize a\n if (aStartsWithAlphabeticCharacter) return -1;\n // b does start with an alphabetic character, but a does not. Prioritize b\n if (bStartsWithAlphabeticCharacter) return 1;\n // neither route has a shortName that starts with an alphabetic character.\n // Return equivalence\n return 0;\n}\n\n/**\n * Checks whether an appropriate comparison of numeric values can be made for\n * sorting purposes. If both values are not valid numbers according to the\n * isNaN check, then this function returns undefined which indicates that a\n * secondary sorting criteria should be used instead. If one value is valid and\n * the other is not, then the valid value will be given sorting priority. If\n * both values are valid numbers, the difference is obtained as the sort value.\n *\n * An optional argument can be provided which will be used to obtain the\n * comparison value from the comparison function arguments.\n *\n * IMPORTANT: the comparison values must be numeric values or at least be\n * attempted to be converted to numeric values! If one of the arguments is\n * something crazy like an empty string, unexpected behavior will occur because\n * JavaScript.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeNumericValueComparator(\n objGetterFn?: (item: Route) => number\n) {\n /* Note: Using the global version of isNaN (the Number version behaves differently. */\n /* eslint-disable no-restricted-globals */\n return (a: number, b: number): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n if (typeof aVal !== \"number\" || typeof bVal !== \"number\") return 0;\n\n // if both values aren't valid numbers, use the next sort criteria\n if (isNaN(aVal) && isNaN(bVal)) return 0;\n // b is a valid number, b gets priority\n if (isNaN(aVal)) return 1;\n // a is a valid number, a gets priority\n if (isNaN(bVal)) return -1;\n // a and b are valid numbers, return the sort value\n return aVal - bVal;\n };\n}\n\n/**\n * Create a comparator function that compares string values. The comparison\n * values feed to the sort comparator function are assumed to be objects that\n * will have either undefined, null or string values at the given key. If one\n * object has undefined, null or an empty string, but the other does have a\n * string with length > 0, then that string will get priority.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeStringValueComparator(\n objGetterFn?: (item: Route) => string\n) {\n return (a: string, b: string): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // both a and b are uncomparable strings, return equivalent value\n if (!aVal && !bVal) return 0;\n // a is not a comparable string, b gets priority\n if (!aVal) return 1;\n // b is not a comparable string, a gets priority\n if (!bVal) return -1;\n // a and b are comparable strings, return the sort value\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n };\n}\n\n/**\n * OpenTripPlanner sets the routeSortOrder to -999 by default. So, if that value\n * is encountered, assume that it actually means that the routeSortOrder is not\n * set in the GTFS.\n *\n * See https://github.com/opentripplanner/OpenTripPlanner/issues/2938\n * Also see https://github.com/opentripplanner/otp-react-redux/issues/122\n */\nfunction getRouteSortOrderValue(val: number): number {\n return val === -999 ? undefined : val;\n}\n\n/**\n * Create a multi-criteria sort comparator function composed of other sort\n * comparator functions. Each comparator function will be ran in the order given\n * until a non-zero comparison value is obtained which is then immediately\n * returned. If all comparison functions return equivalence, then the values\n * are assumed to be equivalent.\n */\nfunction makeMultiCriteriaSort(\n ...criteria: ((a: unknown, b: unknown) => number)[]\n) {\n return (a: number, b: number): number => {\n for (let i = 0; i < criteria.length; i++) {\n const curCriteriaComparatorValue = criteria[i](a, b);\n // if the comparison objects are not equivalent, return the value obtained\n // in this current criteria comparison\n if (curCriteriaComparatorValue !== 0) {\n return curCriteriaComparatorValue;\n }\n }\n return 0;\n };\n}\n\n/**\n * Creates a sort comparator function to compares routes for the purposes of\n * sorting and displaying in a user interface. This takes in a single optional\n * argument which should be a list of transitOperators as defined in the config\n * file. Due to GTFS feeds having varying levels of data quality, a multi-\n * criteria sort is needed to account for various differences. The criteria\n * included here are each applied to the routes in the order listed. If a given\n * sort criterion yields equivalence (e.g., two routes have the short name\n * \"20\"), the comparator falls back onto the next sort criterion (e.g., long\n * name). The sort operates on the following values (in order):\n *\n * 1. Transit Operator. The transit operator will be attempted to be obtained\n * for each route. If no argument is provided when creating this comparator\n * function, then routes will be sorted by their agency's name. If an\n * argument is provided and a match is found based off of the route's feed_id\n * and agency_id and a transitOperator's feed_id and agency_id, then the\n * field transitOperator.order will be used as the comparator value as long\n * as it is numeric. If it is not numeric, a value is returned indicating\n * that this transit operator should be placed at the end of the list.\n * 2. sortOrder. Routes that do not have a valid sortOrder will be placed\n * beneath those that do.\n * 3. route type (OTP mode). See routeTypeComparator code for prioritization of\n * route types.\n * 4. shortNames that begin with alphabetic characters. shortNames that do not\n * start with alphabetic characters will be place beneath those that do.\n * 5. shortName as integer. shortNames that cannot be parsed as integers will\n * be placed beneath those that are valid.\n * 6. shortName as string. Routes without shortNames will be placed beneath\n * those with shortNames.\n * 7. longName as string.\n */\nexport function makeRouteComparator(\n transitOperators: TransitOperator[]\n): (a: number, b: number) => number {\n return makeMultiCriteriaSort(\n makeTransitOperatorComparator(transitOperators),\n makeNumericValueComparator(obj => getRouteSortOrderValue(obj.sortOrder)),\n routeTypeComparator,\n alphabeticShortNameComparator,\n makeNumericValueComparator(obj => parseInt(obj.shortName, 10)),\n makeStringValueComparator(obj => obj.shortName),\n makeStringValueComparator(obj => obj.longName)\n );\n}\n"],"file":"route.js"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Store a javascript object at the specified key.
3
+ */
4
+ export declare function storeItem(key: string, object: unknown): void;
5
+ /**
6
+ * Retrieve a javascript object at the specified key. If not found, defaults to
7
+ * null or, the optionally provided notFoundValue.
8
+ */
9
+ export declare function getItem(key: string, notFoundValue?: unknown): unknown;
10
+ /**
11
+ * Remove item at specified key.
12
+ */
13
+ export declare function removeItem(key: string): void;
14
+ /**
15
+ * Generate a random ID. This might not quite be a UUID, but it serves our
16
+ * purposes for now.
17
+ */
18
+ export declare function randId(): string;
19
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAK5D;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,GAAE,OAAc,GAAG,OAAO,CAY3E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED;;;GAGG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAI/B"}
package/lib/storage.js CHANGED
@@ -7,6 +7,8 @@ exports.storeItem = storeItem;
7
7
  exports.getItem = getItem;
8
8
  exports.removeItem = removeItem;
9
9
  exports.randId = randId;
10
+
11
+ /* eslint-disable no-console */
10
12
  // Prefix to use with local storage keys.
11
13
  const STORAGE_PREFIX = "otp";
12
14
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/storage.js"],"names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","JSON","stringify","getItem","notFoundValue","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"mappings":";;;;;;;;;AAAA;AACA,MAAMA,cAAc,GAAG,KAAvB;AAEA;AACA;AACA;;AACO,SAASC,SAAT,CAAmBC,GAAnB,EAAwBC,MAAxB,EAAgC;AACrCC,EAAAA,MAAM,CAACC,YAAP,CAAoBC,OAApB,CACG,GAAEN,cAAe,IAAGE,GAAI,EAD3B,EAEEK,IAAI,CAACC,SAAL,CAAeL,MAAf,CAFF;AAID;AAED;AACA;AACA;AACA;;;AACO,SAASM,OAAT,CAAiBP,GAAjB,EAAsBQ,aAAa,GAAG,IAAtC,EAA4C;AACjD,MAAIC,YAAJ;;AACA,MAAI;AACFA,IAAAA,YAAY,GAAGP,MAAM,CAACC,YAAP,CAAoBI,OAApB,CAA6B,GAAET,cAAe,IAAGE,GAAI,EAArD,CAAf;AACA,UAAMU,IAAI,GAAGL,IAAI,CAACM,KAAL,CAAWF,YAAX,CAAb;AACA,QAAIC,IAAJ,EAAU,OAAOA,IAAP;AACV,WAAOF,aAAP;AACD,GALD,CAKE,OAAOI,CAAP,EAAU;AACV;AACAC,IAAAA,OAAO,CAACC,IAAR,CAAaF,CAAb,EAAgBH,YAAhB;AACA,WAAOD,aAAP;AACD;AACF;AAED;AACA;AACA;;;AACO,SAASO,UAAT,CAAoBf,GAApB,EAAyB;AAC9BE,EAAAA,MAAM,CAACC,YAAP,CAAoBY,UAApB,CAAgC,GAAEjB,cAAe,IAAGE,GAAI,EAAxD;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASgB,MAAT,GAAkB;AACvB,SAAOC,IAAI,CAACC,MAAL,GACJC,QADI,CACK,EADL,EAEJC,MAFI,CAEG,CAFH,EAEM,CAFN,CAAP;AAGD","sourcesContent":["// Prefix to use with local storage keys.\nconst STORAGE_PREFIX = \"otp\";\n\n/**\n * Store a javascript object at the specified key.\n */\nexport function storeItem(key, object) {\n window.localStorage.setItem(\n `${STORAGE_PREFIX}.${key}`,\n JSON.stringify(object)\n );\n}\n\n/**\n * Retrieve a javascript object at the specified key. If not found, defaults to\n * null or, the optionally provided notFoundValue.\n */\nexport function getItem(key, notFoundValue = null) {\n let itemAsString;\n try {\n itemAsString = window.localStorage.getItem(`${STORAGE_PREFIX}.${key}`);\n const json = JSON.parse(itemAsString);\n if (json) return json;\n return notFoundValue;\n } catch (e) {\n // Catch any errors associated with parsing bad JSON.\n console.warn(e, itemAsString);\n return notFoundValue;\n }\n}\n\n/**\n * Remove item at specified key.\n */\nexport function removeItem(key) {\n window.localStorage.removeItem(`${STORAGE_PREFIX}.${key}`);\n}\n\n/**\n * Generate a random ID. This might not quite be a UUID, but it serves our\n * purposes for now.\n */\nexport function randId() {\n return Math.random()\n .toString(36)\n .substr(2, 9);\n}\n"],"file":"storage.js"}
1
+ {"version":3,"sources":["../src/storage.ts"],"names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","JSON","stringify","getItem","notFoundValue","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"mappings":";;;;;;;;;;AAAA;AACA;AACA,MAAMA,cAAc,GAAG,KAAvB;AAEA;AACA;AACA;;AACO,SAASC,SAAT,CAAmBC,GAAnB,EAAgCC,MAAhC,EAAuD;AAC5DC,EAAAA,MAAM,CAACC,YAAP,CAAoBC,OAApB,CACG,GAAEN,cAAe,IAAGE,GAAI,EAD3B,EAEEK,IAAI,CAACC,SAAL,CAAeL,MAAf,CAFF;AAID;AAED;AACA;AACA;AACA;;;AACO,SAASM,OAAT,CAAiBP,GAAjB,EAA8BQ,aAAsB,GAAG,IAAvD,EAAsE;AAC3E,MAAIC,YAAJ;;AACA,MAAI;AACFA,IAAAA,YAAY,GAAGP,MAAM,CAACC,YAAP,CAAoBI,OAApB,CAA6B,GAAET,cAAe,IAAGE,GAAI,EAArD,CAAf;AACA,UAAMU,IAAI,GAAGL,IAAI,CAACM,KAAL,CAAWF,YAAX,CAAb;AACA,QAAIC,IAAJ,EAAU,OAAOA,IAAP;AACV,WAAOF,aAAP;AACD,GALD,CAKE,OAAOI,CAAP,EAAU;AACV;AACAC,IAAAA,OAAO,CAACC,IAAR,CAAaF,CAAb,EAAgBH,YAAhB;AACA,WAAOD,aAAP;AACD;AACF;AAED;AACA;AACA;;;AACO,SAASO,UAAT,CAAoBf,GAApB,EAAuC;AAC5CE,EAAAA,MAAM,CAACC,YAAP,CAAoBY,UAApB,CAAgC,GAAEjB,cAAe,IAAGE,GAAI,EAAxD;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASgB,MAAT,GAA0B;AAC/B,SAAOC,IAAI,CAACC,MAAL,GACJC,QADI,CACK,EADL,EAEJC,MAFI,CAEG,CAFH,EAEM,CAFN,CAAP;AAGD","sourcesContent":["/* eslint-disable no-console */\n// Prefix to use with local storage keys.\nconst STORAGE_PREFIX = \"otp\";\n\n/**\n * Store a javascript object at the specified key.\n */\nexport function storeItem(key: string, object: unknown): void {\n window.localStorage.setItem(\n `${STORAGE_PREFIX}.${key}`,\n JSON.stringify(object)\n );\n}\n\n/**\n * Retrieve a javascript object at the specified key. If not found, defaults to\n * null or, the optionally provided notFoundValue.\n */\nexport function getItem(key: string, notFoundValue: unknown = null): unknown {\n let itemAsString: string;\n try {\n itemAsString = window.localStorage.getItem(`${STORAGE_PREFIX}.${key}`);\n const json = JSON.parse(itemAsString);\n if (json) return json;\n return notFoundValue;\n } catch (e) {\n // Catch any errors associated with parsing bad JSON.\n console.warn(e, itemAsString);\n return notFoundValue;\n }\n}\n\n/**\n * Remove item at specified key.\n */\nexport function removeItem(key: string): void {\n window.localStorage.removeItem(`${STORAGE_PREFIX}.${key}`);\n}\n\n/**\n * Generate a random ID. This might not quite be a UUID, but it serves our\n * purposes for now.\n */\nexport function randId(): string {\n return Math.random()\n .toString(36)\n .substr(2, 9);\n}\n"],"file":"storage.js"}
package/lib/time.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { Config } from "@opentripplanner/types";
2
+ import { formatTime, formatDurationWithSeconds, formatDuration } from "./deprecated-with-types";
3
+ export { formatTime, formatDuration, formatDurationWithSeconds };
4
+ export declare const OTP_API_DATE_FORMAT = "YYYY-MM-DD";
5
+ export declare const OTP_API_DATE_FORMAT_DATE_FNS = "yyyy-MM-dd";
6
+ export declare const OTP_API_TIME_FORMAT = "HH:mm";
7
+ /**
8
+ * To ease the transition away from moment.js, this method uses date-fns to format durations
9
+ * the way moment.js did.
10
+ * @param {number} seconds The number of seconds to format
11
+ * @param {boolean} showSeconds Whether to render seconds or not
12
+ * @param {boolean} localize If true, will create output like moment.js using date-fns locale.
13
+ * Otherwise, uses date-fns default
14
+ * @returns Formatted duration
15
+ */
16
+ export declare function formatDurationLikeMoment(seconds: number, showSeconds: boolean, localize?: {
17
+ enabled: boolean;
18
+ code: string;
19
+ }): string;
20
+ /**
21
+ * Breaks up a duration in seconds into hours, minutes, and seconds.
22
+ * @param {number} seconds The number of seconds to break up
23
+ * @returns an object with fields with the corresponding, hours, minutes, seconds.
24
+ */
25
+ export declare function toHoursMinutesSeconds(seconds: any): {
26
+ hours: number;
27
+ minutes: number;
28
+ seconds: number;
29
+ };
30
+ /**
31
+ * @param {[type]} config the OTP config object found in store
32
+ * @return {string} the config-defined time formatter or HH:mm (24-hr time)
33
+ */
34
+ export declare function getTimeFormat(config: Config): string;
35
+ export declare function getDateFormat(config: Config): string;
36
+ export declare function getLongDateFormat(config: Config): string;
37
+ /**
38
+ * Offsets a time according to the provided time options
39
+ * and returns the result.
40
+ */
41
+ export declare function offsetTime(ms: any, options: any): any;
42
+ /**
43
+ * Formats a seconds after midnight value for display in narrative
44
+ * @param {number} seconds time since midnight in seconds
45
+ * @param {string} timeFormat A valid date-fns time format
46
+ * @return {string} formatted text representation
47
+ */
48
+ export declare function formatSecondsAfterMidnight(seconds: number, timeFormat: string): string;
49
+ /**
50
+ * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test
51
+ * environment, pulls timezone information from an env variable. Default to
52
+ * GMT+0 if the Intl API is unavailable.
53
+ */
54
+ export declare function getUserTimezone(fallbackTimezone?: string): string;
55
+ /**
56
+ * Formats current time for use in OTP query
57
+ * The conversion to the user's timezone is needed for testing purposes.
58
+ */
59
+ export declare function getCurrentTime(timezone?: string): string;
60
+ /**
61
+ * Formats current date for use in OTP query
62
+ * The conversion to the user's timezone is needed for testing purposes.
63
+ */
64
+ export declare function getCurrentDate(timezone?: string): string;
65
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAUhD,OAAO,EACL,UAAU,EACV,yBAAyB,EACzB,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,yBAAyB,EAAE,CAAC;AAIjE,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAGhD,eAAO,MAAM,4BAA4B,eAAe,CAAC;AACzD,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,OAAO,EACpB,QAAQ,GAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAGzC,GACA,MAAM,CAqCR;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,KAAA;;;;EAQ5C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AACD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAA,EAAE,OAAO,KAAA,OAErC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CAGR;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,gBAAgB,SAAkB,GAAG,MAAM,CAG1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAoB,GAAG,MAAM,CAEnE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAoB,GAAG,MAAM,CAKnE"}
package/lib/time.js CHANGED
@@ -3,24 +3,43 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.formatDurationLikeMoment = formatDurationLikeMoment;
6
7
  exports.toHoursMinutesSeconds = toHoursMinutesSeconds;
7
8
  exports.getTimeFormat = getTimeFormat;
8
9
  exports.getDateFormat = getDateFormat;
9
10
  exports.getLongDateFormat = getLongDateFormat;
10
- exports.formatDuration = formatDuration;
11
- exports.formatDurationWithSeconds = formatDurationWithSeconds;
12
11
  exports.offsetTime = offsetTime;
13
- exports.formatTime = formatTime;
14
12
  exports.formatSecondsAfterMidnight = formatSecondsAfterMidnight;
15
13
  exports.getUserTimezone = getUserTimezone;
16
14
  exports.getCurrentTime = getCurrentTime;
17
15
  exports.getCurrentDate = getCurrentDate;
16
+ Object.defineProperty(exports, "formatTime", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _deprecatedWithTypes.formatTime;
20
+ }
21
+ });
22
+ Object.defineProperty(exports, "formatDurationWithSeconds", {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _deprecatedWithTypes.formatDurationWithSeconds;
26
+ }
27
+ });
28
+ Object.defineProperty(exports, "formatDuration", {
29
+ enumerable: true,
30
+ get: function () {
31
+ return _deprecatedWithTypes.formatDuration;
32
+ }
33
+ });
18
34
  exports.OTP_API_TIME_FORMAT = exports.OTP_API_DATE_FORMAT_DATE_FNS = exports.OTP_API_DATE_FORMAT = void 0;
19
35
 
20
36
  var _dateFns = require("date-fns");
21
37
 
22
38
  var _dateFnsTz = require("date-fns-tz");
23
39
 
40
+ var _deprecatedWithTypes = require("./deprecated-with-types");
41
+
42
+ /* eslint-disable import/no-cycle */
24
43
  // special constants for making sure the following date format is always sent to
25
44
  // OTP regardless of whatever the user has configured as the display format
26
45
  const OTP_API_DATE_FORMAT = "YYYY-MM-DD"; // Date-Fns uses a different string format than moment.js
@@ -114,31 +133,6 @@ function getLongDateFormat(config) {
114
133
 
115
134
  return (config === null || config === void 0 ? void 0 : (_config$dateTime3 = config.dateTime) === null || _config$dateTime3 === void 0 ? void 0 : _config$dateTime3.longDateFormat) || "D MMMM YYYY";
116
135
  }
117
- /**
118
- * Formats an elapsed time duration for display in narrative.
119
- * TODO: internationalization
120
- * @param {number} seconds duration in seconds
121
- * @returns {string} formatted text representation
122
- */
123
-
124
-
125
- function formatDuration(seconds) {
126
- return formatDurationLikeMoment(seconds, false);
127
- }
128
- /**
129
- * Formats an elapsed time in seconds, minutes, hours duration for display in narrative
130
- * @param {number} seconds duration in seconds
131
- * @param {object} region an object that allows internationalization of the time
132
- * @returns {string} formatted text representation
133
- */
134
-
135
-
136
- function formatDurationWithSeconds(seconds, region) {
137
- return formatDurationLikeMoment(seconds, {
138
- enabled: true,
139
- code: region
140
- });
141
- }
142
136
  /**
143
137
  * Offsets a time according to the provided time options
144
138
  * and returns the result.
@@ -148,17 +142,6 @@ function formatDurationWithSeconds(seconds, region) {
148
142
  function offsetTime(ms, options) {
149
143
  return ms + ((options === null || options === void 0 ? void 0 : options.offset) || 0);
150
144
  }
151
- /**
152
- * Formats a time value for display in narrative
153
- * TODO: internationalization/timezone
154
- * @param {number} ms epoch time value in milliseconds
155
- * @returns {string} formatted text representation
156
- */
157
-
158
-
159
- function formatTime(ms, options) {
160
- return (0, _dateFns.format)(offsetTime(ms, options), (options === null || options === void 0 ? void 0 : options.format) || OTP_API_TIME_FORMAT);
161
- }
162
145
  /**
163
146
  * Formats a seconds after midnight value for display in narrative
164
147
  * @param {number} seconds time since midnight in seconds