@opentripplanner/core-utils 15.0.0 → 16.0.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 (58) hide show
  1. package/esm/index.js +3 -0
  2. package/esm/index.js.map +1 -1
  3. package/esm/itinerary.js +104 -78
  4. package/esm/itinerary.js.map +1 -1
  5. package/esm/map.js +2 -2
  6. package/esm/map.js.map +1 -1
  7. package/esm/query-gen.js +9 -5
  8. package/esm/query-gen.js.map +1 -1
  9. package/esm/route.js +26 -20
  10. package/esm/route.js.map +1 -1
  11. package/esm/storage.js +4 -1
  12. package/esm/storage.js.map +1 -1
  13. package/esm/time.js +6 -5
  14. package/esm/time.js.map +1 -1
  15. package/esm/ui.js +4 -2
  16. package/esm/ui.js.map +1 -1
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +6 -0
  19. package/lib/index.js.map +1 -1
  20. package/lib/itinerary.d.ts +20 -11
  21. package/lib/itinerary.d.ts.map +1 -1
  22. package/lib/itinerary.js +96 -85
  23. package/lib/itinerary.js.map +1 -1
  24. package/lib/map.d.ts +2 -2
  25. package/lib/map.d.ts.map +1 -1
  26. package/lib/map.js +1 -1
  27. package/lib/map.js.map +1 -1
  28. package/lib/query-gen.d.ts +1 -19
  29. package/lib/query-gen.d.ts.map +1 -1
  30. package/lib/query-gen.js +9 -5
  31. package/lib/query-gen.js.map +1 -1
  32. package/lib/route.d.ts +10 -8
  33. package/lib/route.d.ts.map +1 -1
  34. package/lib/route.js +22 -16
  35. package/lib/route.js.map +1 -1
  36. package/lib/storage.d.ts +1 -1
  37. package/lib/storage.d.ts.map +1 -1
  38. package/lib/storage.js +4 -1
  39. package/lib/storage.js.map +1 -1
  40. package/lib/time.d.ts +3 -1
  41. package/lib/time.d.ts.map +1 -1
  42. package/lib/time.js +5 -4
  43. package/lib/time.js.map +1 -1
  44. package/lib/ui.d.ts.map +1 -1
  45. package/lib/ui.js +4 -2
  46. package/lib/ui.js.map +1 -1
  47. package/package.json +9 -7
  48. package/src/__tests__/itinerary.ts +64 -6
  49. package/src/index.ts +3 -0
  50. package/src/itinerary.ts +145 -97
  51. package/src/map.ts +5 -3
  52. package/src/query-gen.ts +15 -9
  53. package/src/route.ts +65 -38
  54. package/src/storage.ts +8 -2
  55. package/src/time.ts +7 -6
  56. package/src/ui.ts +8 -6
  57. package/tsconfig.json +1 -0
  58. package/tsconfig.tsbuildinfo +1 -1
package/lib/itinerary.js CHANGED
@@ -103,10 +103,11 @@ function legContainsGeometry(leg) {
103
103
  }
104
104
  function isAdvanceBookingRequired(info) {
105
105
  var _info$latestBookingTi;
106
- return (info === null || info === void 0 || (_info$latestBookingTi = info.latestBookingTime) === null || _info$latestBookingTi === void 0 ? void 0 : _info$latestBookingTi.daysPrior) > 0;
106
+ const daysPrior = info === null || info === void 0 || (_info$latestBookingTi = info.latestBookingTime) === null || _info$latestBookingTi === void 0 ? void 0 : _info$latestBookingTi.daysPrior;
107
+ return typeof daysPrior === "number" && daysPrior > 0;
107
108
  }
108
109
  function legDropoffRequiresAdvanceBooking(leg) {
109
- return isAdvanceBookingRequired(leg === null || leg === void 0 ? void 0 : leg.dropOffBookingInfo);
110
+ return isAdvanceBookingRequired(leg.dropOffBookingInfo);
110
111
  }
111
112
 
112
113
  /**
@@ -199,6 +200,7 @@ function hasRental(modesStr) {
199
200
  return modesStr.split(",").some(mode => mode.indexOf("_RENT") > -1);
200
201
  }
201
202
  function getMapColor(mode) {
203
+ // @ts-expect-error this is not typed
202
204
  mode = mode || this.get("mode");
203
205
  if (mode === "WALK") return "#444";
204
206
  if (mode === "BICYCLE") return "#0073e5";
@@ -234,14 +236,15 @@ function getCompanyFromLeg(leg) {
234
236
  rentedVehicle,
235
237
  rideHailingEstimate
236
238
  } = leg;
239
+ const firstNetwork = Array.isArray(from.networks) && from.networks.length > 0 ? from.networks[0] : null;
237
240
  if (mode === "CAR" && rentedCar) {
238
- return from.networks[0];
241
+ return firstNetwork;
239
242
  }
240
243
  if (mode === "CAR" && rideHailingEstimate) {
241
244
  return rideHailingEstimate.provider.id;
242
245
  }
243
- if (mode === "BICYCLE" && rentedBike && from.networks) {
244
- return from.networks[0];
246
+ if (mode === "BICYCLE" && rentedBike) {
247
+ return firstNetwork;
245
248
  }
246
249
  if (from.rentalVehicle) {
247
250
  return from.rentalVehicle.network;
@@ -249,16 +252,16 @@ function getCompanyFromLeg(leg) {
249
252
  if ((_from$vehicleRentalSt = from.vehicleRentalStation) !== null && _from$vehicleRentalSt !== void 0 && _from$vehicleRentalSt.rentalNetwork) {
250
253
  return from.vehicleRentalStation.rentalNetwork.networkId;
251
254
  }
252
- if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle && from.networks) {
253
- return from.networks[0];
255
+ if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle) {
256
+ return firstNetwork;
254
257
  }
255
258
  return null;
256
259
  }
257
260
  function getItineraryBounds(itinerary) {
258
- let coords = [];
261
+ const coords = [];
259
262
  itinerary.legs.forEach(leg => {
260
263
  const legCoords = _polyline.default.toGeoJSON(leg.legGeometry.points).coordinates.map(c => [c[1], c[0]]);
261
- coords = [...coords, ...legCoords];
264
+ coords.push(...legCoords);
262
265
  });
263
266
  return coords;
264
267
  }
@@ -279,51 +282,46 @@ function getLegBounds(leg) {
279
282
  }
280
283
 
281
284
  /* Returns an interpolated lat-lon at a specified distance along a leg */
282
-
283
285
  function legLocationAtDistance(leg, distance) {
284
- if (!leg.legGeometry) return null;
286
+ if (!leg.legGeometry) return undefined;
285
287
  try {
288
+ var _pt$geometry;
286
289
  const line = _polyline.default.toGeoJSON(leg.legGeometry.points);
287
290
  const pt = (0, _along.default)(line, distance, {
288
291
  units: "meters"
289
292
  });
290
- if (pt && pt.geometry && pt.geometry.coordinates) {
291
- return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];
292
- }
293
- } catch (e) {
294
- // FIXME handle error!
293
+ const coords = pt === null || pt === void 0 || (_pt$geometry = pt.geometry) === null || _pt$geometry === void 0 ? void 0 : _pt$geometry.coordinates;
294
+ return [coords[1], coords[0]];
295
+ } catch {
296
+ // This is designed to catch the toGeoJSON from throwing if the geometry is not in the correct format
295
297
  }
296
298
  return null;
297
299
  }
298
300
 
299
- /* Returns an interpolated elevation at a specified distance along a leg */
301
+ /**
302
+ * Returns an interpolated elevation at a specified distance along a leg
303
+ * @param points - The points of the elevation profile. Each point is a tuple of [distance, elevation].
304
+ * @param distance - The distance along the leg to interpolate the elevation at
305
+ * @returns The interpolated elevation at the specified distance
306
+ */
300
307
 
301
308
  function legElevationAtDistance(points, distance) {
302
- // Iterate through the combined elevation profile
303
- let traversed = 0;
304
- // If first point distance is not zero, insert starting point at zero with
305
- // null elevation. Encountering this value should trigger the warning below.
306
- if (points[0][0] > 0) {
307
- points.unshift([0, null]);
308
- }
309
- for (let i = 1; i < points.length; i++) {
310
- const start = points[i - 1];
311
- const elevDistanceSpan = points[i][0] - start[0];
312
- if (distance >= traversed && distance <= traversed + elevDistanceSpan) {
313
- // Distance falls within this point and the previous one;
314
- // compute & return interpolated elevation value
315
- if (start[1] === null) {
316
- console.warn("Elevation value does not exist for distance.", distance, traversed);
317
- return null;
318
- }
319
- const pct = (distance - traversed) / elevDistanceSpan;
320
- const elevSpan = points[i][1] - start[1];
321
- return start[1] + elevSpan * pct;
309
+ const elevation = points.reduce((acc, point, index) => {
310
+ const prevPoint = points[index - 1];
311
+ // at the first index there is no previous point
312
+ if (!prevPoint) return acc;
313
+ const [pointDistance, pointElevation] = point;
314
+ const [prevPointDistance, prevPointElevation] = prevPoint;
315
+ if (distance >= prevPointDistance && distance <= pointDistance) {
316
+ return prevPointElevation + (pointElevation - prevPointElevation) * (distance - prevPointDistance) / (pointDistance - prevPointDistance);
322
317
  }
323
- traversed += elevDistanceSpan;
318
+ return acc;
319
+ }, undefined);
320
+ if (elevation === undefined) {
321
+ console.warn("Elevation value does not exist for distance.", distance);
322
+ return undefined;
324
323
  }
325
- console.warn("Elevation value does not exist for distance.", distance, traversed);
326
- return null;
324
+ return elevation;
327
325
  }
328
326
  function mapOldElevationComponentToNew(oldElev) {
329
327
  return {
@@ -396,6 +394,7 @@ function getTextWidth(text, font = "22px Arial") {
396
394
  // reuse canvas object for better performance
397
395
  const canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
398
396
  const context = canvas.getContext("2d");
397
+ if (!context) return 0;
399
398
  context.font = font;
400
399
  const metrics = context.measureText(text);
401
400
  return metrics.width;
@@ -450,21 +449,16 @@ function calculatePhysicalActivity(itinerary) {
450
449
  * It is assumed that the same currency is used for all TNC legs.
451
450
  */
452
451
  function calculateTncFares(itinerary) {
453
- return itinerary.legs.filter(leg => leg.mode === "CAR" && leg.rideHailingEstimate).reduce(({
454
- maxTNCFare,
455
- minTNCFare
456
- }, {
457
- rideHailingEstimate
458
- }) => {
452
+ return itinerary.legs.filter(leg => leg.mode === "CAR" && leg.rideHailingEstimate !== undefined).reduce((acc, leg) => {
459
453
  const {
460
454
  minPrice,
461
455
  maxPrice
462
- } = rideHailingEstimate;
456
+ } = leg.rideHailingEstimate;
463
457
  return {
464
458
  // Assumes a single currency for entire itinerary.
465
459
  currencyCode: minPrice.currency.code,
466
- maxTNCFare: maxTNCFare + maxPrice.amount,
467
- minTNCFare: minTNCFare + minPrice.amount
460
+ maxTNCFare: acc.maxTNCFare + maxPrice.amount,
461
+ minTNCFare: acc.minTNCFare + minPrice.amount
468
462
  };
469
463
  }, {
470
464
  currencyCode: null,
@@ -562,7 +556,7 @@ const zeroDollars = currency => ({
562
556
  amount: 0,
563
557
  currency
564
558
  });
565
-
559
+ exports.zeroDollars = zeroDollars;
566
560
  /**
567
561
  * Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
568
562
  * @param leg Leg with Fares v2 information
@@ -574,7 +568,6 @@ const zeroDollars = currency => ({
574
568
  * all the information needed, but the other fields are kept to
575
569
  * make the transition to Fares V2 less jarring.
576
570
  */
577
- exports.zeroDollars = zeroDollars;
578
571
  function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
579
572
  if (!leg.fareProducts) return {
580
573
  price: undefined
@@ -592,16 +585,19 @@ function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
592
585
  return productRiderCategoryId === riderCategoryId && productMediaId === mediumId && (// Make sure there's a price
593
586
  // Some fare products don't have a price at all.
594
587
  product === null || product === void 0 ? void 0 : product.price);
588
+ })
589
+ // Make sure there's a price
590
+ // Some fare products don't have a price at all.
591
+ .filter(fare => {
592
+ var _fare$product;
593
+ return ((_fare$product = fare.product) === null || _fare$product === void 0 ? void 0 : _fare$product.price) !== undefined;
595
594
  }).map(fare => {
596
- const alreadySeen = (seenFareIds === null || seenFareIds === void 0 ? void 0 : seenFareIds.indexOf(fare.id)) > -1;
597
- const {
598
- currency
599
- } = fare.product.price;
595
+ const alreadySeen = !!seenFareIds && (seenFareIds === null || seenFareIds === void 0 ? void 0 : seenFareIds.indexOf(fare.id)) > -1;
600
596
  return {
601
597
  id: fare.id,
602
598
  product: {
603
599
  ...fare.product,
604
- legPrice: alreadySeen ? zeroDollars(currency) : fare.product.price
600
+ legPrice: alreadySeen && fare.product.price ? zeroDollars(fare.product.price.currency) : fare.product.price
605
601
  }
606
602
  };
607
603
  }).sort((a, b) => {
@@ -630,37 +626,46 @@ function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
630
626
  * @param category Rider category (youth, regular, senior)
631
627
  * @param container Fare container (cash, electronic)
632
628
  * @param seenFareIds List of fare product IDs that have already been seen on prev legs.
629
+ * @param nulledTotalFareOnAnyMissingFare If this is set to true, the total fare
630
+ * will be null if *any* fare is missing. If false, the total will be the total
631
+ * fare with the missing fares ignored.
633
632
  * @returns Money object for the total itinerary cost.
634
633
  */
635
- function getItineraryCost(legs, mediumId, riderCategoryId) {
636
- // TODO: Better input type handling
634
+ function getItineraryCost(legs, mediumId, riderCategoryId, nulledTotalFareOnAnyMissingFare = false) {
637
635
  if (Array.isArray(mediumId) || Array.isArray(riderCategoryId)) {
638
- if ((mediumId === null || mediumId === void 0 ? void 0 : mediumId.length) !== riderCategoryId.length) {
639
- console.warn("Invalid input types, only using first item. medium id list and rider category list must have same number of items");
640
- return getItineraryCost(legs, mediumId[0], riderCategoryId[0]);
641
- }
642
- let total = {
643
- amount: 0,
644
- currency: null
645
- };
646
- for (let i = 0; i < mediumId.length; i++) {
647
- const newCost = getItineraryCost(legs, mediumId[i], riderCategoryId[i]);
648
- if (newCost) {
649
- var _total, _total$currency;
650
- total = {
651
- amount: ((_total = total) === null || _total === void 0 ? void 0 : _total.amount) + ((newCost === null || newCost === void 0 ? void 0 : newCost.amount) || 0),
652
- currency: (_total$currency = total.currency) !== null && _total$currency !== void 0 ? _total$currency : newCost === null || newCost === void 0 ? void 0 : newCost.currency
653
- };
636
+ // TODO: Better input type handling
637
+ if (Array.isArray(mediumId) && Array.isArray(riderCategoryId)) {
638
+ var _total$currency;
639
+ if (mediumId.length !== riderCategoryId.length) {
640
+ console.warn("Invalid input types, only using first item. medium id list and rider category list must have same number of items");
641
+ return getItineraryCost(legs, mediumId[0], riderCategoryId[0]);
654
642
  }
643
+ const total = mediumId.reduce((acc, currentMediumId, index) => {
644
+ var _newCost$currency;
645
+ const newCost = getItineraryCost(legs, currentMediumId, riderCategoryId[index]);
646
+ if (!newCost) return acc;
647
+ return {
648
+ amount: acc.amount + (newCost.amount || 0),
649
+ currency: acc.currency.code !== "" ? acc.currency : (_newCost$currency = newCost.currency) !== null && _newCost$currency !== void 0 ? _newCost$currency : acc.currency
650
+ };
651
+ }, {
652
+ amount: 0,
653
+ currency: {
654
+ code: "",
655
+ digits: 0
656
+ }
657
+ });
658
+ if (!((_total$currency = total.currency) !== null && _total$currency !== void 0 && _total$currency.code)) return undefined;
659
+ return total;
655
660
  }
656
- if (total.currency === null) return undefined;
657
- return total;
661
+ console.warn("Invalid input types, only using first item. medium id list and rider category list must have same number of items");
662
+ return undefined;
658
663
  }
659
664
  const legCosts = legs
660
665
  // Only legs with fares (no walking legs)
661
666
  .filter(leg => {
662
667
  var _leg$fareProducts;
663
- return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) > 0;
668
+ return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) && leg.fareProducts.length > 0;
664
669
  })
665
670
  // Get the leg cost object of each leg
666
671
  .reduce((acc, leg) => {
@@ -673,6 +678,7 @@ function getItineraryCost(legs, mediumId, riderCategoryId) {
673
678
  productUseId
674
679
  } = getLegCost(leg, mediumId, riderCategoryId, acc.seenIds);
675
680
  if (!appliedFareProduct) return acc;
681
+ if (!productUseId) return acc;
676
682
  return {
677
683
  legCosts: [...acc.legCosts, appliedFareProduct],
678
684
  seenIds: [...acc.seenIds, productUseId]
@@ -681,17 +687,22 @@ function getItineraryCost(legs, mediumId, riderCategoryId) {
681
687
  seenIds: [],
682
688
  legCosts: []
683
689
  }).legCosts.map(lc => lc.legPrice);
690
+ if (nulledTotalFareOnAnyMissingFare && legs.filter(l => l.transitLeg).length !== legCosts.length) {
691
+ return undefined;
692
+ }
684
693
  if (legCosts.length === 0) return undefined;
685
694
  // Calculate the total
686
- return legCosts.reduce((prev, cur) => {
687
- var _prev$currency;
688
- return {
689
- amount: prev.amount + (cur === null || cur === void 0 ? void 0 : cur.amount) || 0,
690
- currency: (_prev$currency = prev.currency) !== null && _prev$currency !== void 0 ? _prev$currency : cur === null || cur === void 0 ? void 0 : cur.currency
691
- };
692
- }, {
695
+ return legCosts.reduce((prev, cur) => ({
696
+ amount: prev.amount + (cur === null || cur === void 0 ? void 0 : cur.amount) || 0,
697
+ currency: prev.currency.code !== "" ? prev.currency : cur.currency
698
+ }),
699
+ // eslint-disable-next-line prettier/prettier -- old eslint doesn't know satisfies
700
+ {
693
701
  amount: 0,
694
- currency: null
702
+ currency: {
703
+ code: "",
704
+ digits: 0
705
+ }
695
706
  });
696
707
  }
697
708
  const pickupDropoffTypeToOtp1 = otp2Type => {
@@ -1 +1 @@
1
- {"version":3,"file":"itinerary.js","names":["_polyline","_interopRequireDefault","require","_along","transitModes","exports","getTransitModes","config","modes","map","tm","mode","isTransitLeg","leg","transitLeg","isTransit","includes","isReservationRequired","boardRule","alightRule","isCoordinationRequired","containsGeometry","place","_place$stop","_place$stop2","stop","geometries","undefined","endsWithGeometry","to","startsWithGeometry","from","legContainsGeometry","isAdvanceBookingRequired","info","_info$latestBookingTi","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isFlex","_leg$stopCalls","stopCalls","some","call","_call$stopLocation","stopLocation","__typename","startsWith","isRideshareLeg","_leg$rideHailingEstim","rideHailingEstimate","provider","id","isWalk","isBicycle","isBicycleRent","isCar","isMicromobility","isAccessMode","hasTransit","modesStr","split","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","_from$vehicleRentalSt","rentedBike","rentedCar","rentedVehicle","networks","rentalVehicle","network","vehicleRentalStation","rentalNetwork","networkId","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","polyline","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","legLocationAtDistance","distance","line","pt","turfAlong","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","mapOldElevationComponentToNew","oldElev","first","elevation","second","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","_step$elevation","stepElevationProfile","elevationProfile","Array","isArray","elev","diff","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","company","find","co","getCompaniesLabelFromNetworks","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","reduce","maxTNCFare","minTNCFare","minPrice","maxPrice","currencyCode","currency","code","amount","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","trolleybus","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","_itinerary$legs","carbonIntensityWithDefaults","totalCarbon","total","getDisplayedStopCode","placeOrStop","_placeOrStop$stopCode","stopCode","_placeOrStop$code","descope","item","index","substring","zeroDollars","getLegCost","mediumId","riderCategoryId","seenFareIds","fareProducts","price","relevantFareProducts","product","_product$riderCategor","_product$riderCategor2","_product$medium","_product$medium2","productRiderCategoryId","riderCategory","productMediaId","medium","fare","alreadySeen","legPrice","sort","a","b","_a$product","_b$product","cheapestRelevantFareProduct","alternateFareProducts","splice","fp","appliedFareProduct","isDependent","productUseId","getItineraryCost","newCost","_total","_total$currency","legCosts","_leg$fareProducts","acc","seenIds","lc","prev","cur","_prev$currency","pickupDropoffTypeToOtp1","otp2Type","convertGraphQLResponseToLegacy","_leg$agency","_leg$agency2","_leg$agency3","_leg$agency4","_leg$from$stop","_leg$from$stop2","_leg$route","_leg$route2","_leg$route3","_leg$route4","_leg$route5","_leg$route6","_leg$to$stop","_leg$to$stop2","_leg$trip","_leg$trip2","agencyBrandingUrl","agency","url","agencyId","agencyName","name","agencyUrl","dropoffType","pickupType","bookingRuleInfo","dropOff","pickUp","pickupBookingInfo","stopId","gtfsId","route","shortName","routeColor","color","routeId","routeLongName","longName","routeShortName","routeTextColor","textColor","tripHeadsign","trip","tripId","getLegRouteShortName","getLegRouteLongName","getLegRouteName"],"sources":["../src/itinerary.ts"],"sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n AppliedFareProduct,\n Company,\n Config,\n Currency,\n ElevationProfile,\n ElevationProfileComponent,\n FlexBookingInfo,\n ItineraryOnlyLegsRequired,\n LatLngArray,\n Leg,\n MassUnitOption,\n Money,\n Place,\n Step,\n Stop,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"TROLLEYBUS\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransitLeg(leg: Leg): boolean {\n return leg.transitLeg;\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg?.boardRule === \"mustPhone\" || leg?.alightRule === \"mustPhone\";\n}\n/**\n * Returns true if a user must ask the driver to let the user off\n * or if the user must flag the driver down for pickup.\n * \"coordinateWithDriver\" in board/alight rule encodes this info.\n */\nexport function isCoordinationRequired(leg: Leg): boolean {\n return (\n leg?.boardRule === \"coordinateWithDriver\" ||\n leg?.alightRule === \"coordinateWithDriver\"\n );\n}\n\nexport function containsGeometry(place: Place): boolean {\n return (\n place?.stop?.geometries !== null && place?.stop?.geometries !== undefined\n );\n}\nexport function endsWithGeometry(leg: Leg): boolean {\n return containsGeometry(leg?.to);\n}\nexport function startsWithGeometry(leg: Leg): boolean {\n return containsGeometry(leg?.from);\n}\nexport function legContainsGeometry(leg: Leg): boolean {\n return endsWithGeometry(leg) || startsWithGeometry(leg);\n}\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg?.dropOffBookingInfo);\n}\n\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return (\n leg?.stopCalls?.some(call =>\n // Flex calls are \"Location\" or \"LocationGroup\"\n // eslint-disable-next-line no-underscore-dangle\n call?.stopLocation?.__typename.startsWith(\"Location\")\n ) || false\n );\n}\nexport function isRideshareLeg(leg: Leg): boolean {\n return !!leg.rideHailingEstimate?.provider?.id;\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TROLLEYBUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const {\n from,\n mode,\n rentedBike,\n rentedCar,\n rentedVehicle,\n rideHailingEstimate\n } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && rideHailingEstimate) {\n return rideHailingEstimate.provider.id;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (from.rentalVehicle) {\n return from.rentalVehicle.network;\n }\n if (from.vehicleRentalStation?.rentalNetwork) {\n return from.vehicleRentalStation.rentalNetwork.networkId;\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(\n itinerary: ItineraryOnlyLegsRequired\n): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[][] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return interpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\nexport function mapOldElevationComponentToNew(oldElev: {\n first: number;\n second: number;\n}): ElevationProfileComponent {\n return {\n distance: oldElev.first,\n elevation: oldElev.second\n };\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous: ElevationProfileComponent | null = null;\n const points = [];\n steps.forEach(step => {\n // Support for old REST response data (in step.elevation)\n const stepElevationProfile =\n step.elevationProfile ||\n (Array.isArray(step.elevation) &&\n step.elevation?.map<ElevationProfileComponent>(\n mapOldElevationComponentToNew\n ));\n\n if (!stepElevationProfile || stepElevationProfile.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < stepElevationProfile.length; i++) {\n const elev = stepElevationProfile[i];\n if (previous) {\n const diff = (elev.elevation - previous.elevation) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.distance !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.elevation * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.distance, elev.elevation]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (\n i === stepElevationProfile.length - 1 &&\n elev.distance !== step.distance\n ) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including reused canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // reuse canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks. Returns\n * empty string if no networks provided.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks?: string[] | string,\n companies: Company[] = []\n): string {\n if (!networks) return \"\";\n return (Array.isArray(networks) ? networks : [networks])\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: ItineraryOnlyLegsRequired\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(\n itinerary: ItineraryOnlyLegsRequired\n): TncFare {\n return itinerary.legs\n .filter(leg => leg.mode === \"CAR\" && leg.rideHailingEstimate)\n .reduce(\n ({ maxTNCFare, minTNCFare }, { rideHailingEstimate }) => {\n const { minPrice, maxPrice } = rideHailingEstimate;\n return {\n // Assumes a single currency for entire itinerary.\n currencyCode: minPrice.currency.code,\n maxTNCFare: maxTNCFare + maxPrice.amount,\n minTNCFare: minTNCFare + minPrice.amount\n };\n },\n {\n currencyCode: null,\n maxTNCFare: 0,\n minTNCFare: 0\n }\n );\n}\n\n/**\n * Sources:\n * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf\n * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey\n * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx\n * Other values extrapolated.\n */\nconst CARBON_INTENSITY_DEFAULTS = {\n walk: 0.026,\n bicycle: 0.017,\n car: 0.162,\n tram: 0.066,\n trolleybus: 0.066,\n subway: 0.066,\n rail: 0.066,\n bus: 0.09,\n ferry: 0.082,\n cable_car: 0.021,\n gondola: 0.021,\n funicular: 0.066,\n transit: 0.066,\n leg_switch: 0,\n airplane: 0.382,\n micromobility: 0.095\n};\n\n/**\n * @param {itinerary} itinerary OTP trip itinierary, only legs is required.\n * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter\n * @param {units} units units to be used in return value\n * @return Amount of carbon in chosen unit\n */\nexport function calculateEmissions(\n // This type makes all the properties from Itinerary optional except legs.\n itinerary: ItineraryOnlyLegsRequired,\n carbonIntensity: Record<string, number> = {},\n units?: MassUnitOption\n): number {\n // Apply defaults for any values that we don't have.\n const carbonIntensityWithDefaults = {\n ...CARBON_INTENSITY_DEFAULTS,\n ...carbonIntensity\n };\n\n // Distance is in meters, totalCarbon is in grams\n const totalCarbon =\n itinerary?.legs?.reduce((total, leg) => {\n return (\n (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||\n 0) + total\n );\n }, 0) || 0;\n\n switch (units) {\n case \"ounce\":\n return totalCarbon / 28.35;\n case \"kilogram\":\n return totalCarbon / 1000;\n case \"pound\":\n return totalCarbon / 454;\n case \"gram\":\n default:\n return totalCarbon;\n }\n}\n\n/**\n * Returns the user-facing stop code to display for a stop or place\n */\nexport function getDisplayedStopCode(\n placeOrStop: Place | Stop\n): string | undefined {\n if (\"stopId\" in placeOrStop) {\n return placeOrStop.stopCode ?? undefined;\n }\n if (\"id\" in placeOrStop) {\n return placeOrStop.code ?? undefined;\n }\n return undefined;\n}\n\n/**\n * Removes the first part of the OTP standard scope (\":\"), if it is present.\n * @param item String that is potentially scoped with `:` character\n * @returns descoped string\n */\nexport const descope = (item?: string | null): string | null | undefined => {\n if (!item) return item;\n const index = item.indexOf(\":\");\n return index === -1 ? item : item.substring(index + 1);\n};\n\nexport type ExtendedMoney = Money & { originalAmount?: number };\n\nexport const zeroDollars = (currency: Currency): Money => ({\n amount: 0,\n currency\n});\n\n/**\n * Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.\n * @param leg Leg with Fares v2 information\n * @param mediumId Desired medium ID to calculate fare for\n * @param riderCategoryId Desire rider category to calculate fare for\n * @param seenFareIds Fare IDs used on previous legs. Used to detect transfer discounts.\n * @returns Object containing price as well as transfer/dependent\n * fare information. `AppliedFareProduct` should contain\n * all the information needed, but the other fields are kept to\n * make the transition to Fares V2 less jarring.\n */\nexport function getLegCost(\n leg: Leg,\n mediumId?: string | null,\n riderCategoryId?: string | null,\n seenFareIds?: string[]\n): {\n alternateFareProducts?: AppliedFareProduct[];\n appliedFareProduct?: AppliedFareProduct;\n isDependent?: boolean;\n price?: Money;\n productUseId?: string;\n} {\n if (!leg.fareProducts) return { price: undefined };\n const relevantFareProducts = leg.fareProducts\n .filter(({ product }) => {\n // riderCategory and medium can be specifically defined as null to handle\n // generic GTFS based fares from OTP when there is no fare model\n\n // Remove (optional) agency scoping\n const productRiderCategoryId =\n descope(product?.riderCategory?.id) ||\n product?.riderCategory?.id ||\n null;\n\n const productMediaId =\n descope(product?.medium?.id) || product?.medium?.id || null;\n\n return (\n productRiderCategoryId === riderCategoryId &&\n productMediaId === mediumId &&\n // Make sure there's a price\n // Some fare products don't have a price at all.\n product?.price\n );\n })\n .map(fare => {\n const alreadySeen = seenFareIds?.indexOf(fare.id) > -1;\n const { currency } = fare.product.price;\n return {\n id: fare.id,\n product: {\n ...fare.product,\n legPrice: alreadySeen ? zeroDollars(currency) : fare.product.price\n } as AppliedFareProduct\n };\n })\n .sort((a, b) => a.product?.legPrice?.amount - b.product?.legPrice?.amount);\n\n // Return the cheapest, but include other matches as well\n const cheapestRelevantFareProduct = relevantFareProducts[0];\n\n // TODO: return one object here instead of dumbing it down?\n return {\n alternateFareProducts: relevantFareProducts.splice(1).map(fp => fp.product),\n appliedFareProduct: cheapestRelevantFareProduct?.product,\n isDependent:\n // eslint-disable-next-line no-underscore-dangle\n cheapestRelevantFareProduct?.product.__typename ===\n \"DependentFareProduct\",\n price: cheapestRelevantFareProduct?.product.legPrice,\n productUseId: cheapestRelevantFareProduct?.id\n };\n}\n\n/**\n * Returns the total itinerary cost for a given set of legs.\n * @param legs Itinerary legs with fare products (must have used getLegsWithFares)\n * @param category Rider category (youth, regular, senior)\n * @param container Fare container (cash, electronic)\n * @param seenFareIds List of fare product IDs that have already been seen on prev legs.\n * @returns Money object for the total itinerary cost.\n */\nexport function getItineraryCost(\n legs: Leg[],\n mediumId?: string | string[] | null,\n riderCategoryId?: string | string[] | null\n): Money | undefined {\n // TODO: Better input type handling\n if (Array.isArray(mediumId) || Array.isArray(riderCategoryId)) {\n if (mediumId?.length !== riderCategoryId.length) {\n console.warn(\n \"Invalid input types, only using first item. medium id list and rider category list must have same number of items\"\n );\n return getItineraryCost(legs, mediumId[0], riderCategoryId[0]);\n }\n\n let total = { amount: 0, currency: null };\n for (let i = 0; i < mediumId.length; i++) {\n const newCost = getItineraryCost(legs, mediumId[i], riderCategoryId[i]);\n if (newCost) {\n total = {\n amount: total?.amount + (newCost?.amount || 0),\n currency: total.currency ?? newCost?.currency\n };\n }\n }\n if (total.currency === null) return undefined;\n return total;\n }\n\n const legCosts = legs\n // Only legs with fares (no walking legs)\n .filter(leg => leg.fareProducts?.length > 0)\n // Get the leg cost object of each leg\n .reduce<{ seenIds: string[]; legCosts: AppliedFareProduct[] }>(\n (acc, leg) => {\n // getLegCost handles filtering out duplicate use IDs\n // One fare product can be used on multiple legs,\n // and we don't want to count it more than once.\n // Use an object keyed by productUseId to deduplicate, then extract prices\n const { appliedFareProduct, productUseId } = getLegCost(\n leg,\n mediumId,\n riderCategoryId,\n acc.seenIds\n );\n if (!appliedFareProduct) return acc;\n return {\n legCosts: [...acc.legCosts, appliedFareProduct],\n seenIds: [...acc.seenIds, productUseId]\n };\n },\n { seenIds: [], legCosts: [] }\n )\n .legCosts.map(lc => lc.legPrice);\n\n if (legCosts.length === 0) return undefined;\n // Calculate the total\n return legCosts.reduce<Money>(\n (prev, cur) => ({\n amount: prev.amount + cur?.amount || 0,\n currency: prev.currency ?? cur?.currency\n }),\n { amount: 0, currency: null }\n );\n}\n\nconst pickupDropoffTypeToOtp1 = (otp2Type: string): string | null => {\n switch (otp2Type) {\n case \"COORDINATE_WITH_DRIVER\":\n return \"coordinateWithDriver\";\n case \"CALL_AGENCY\":\n return \"mustPhone\";\n case \"SCHEDULED\":\n return \"scheduled\";\n case \"NONE\":\n return \"none\";\n default:\n return null;\n }\n};\n\nexport const convertGraphQLResponseToLegacy = (leg: any): any => ({\n ...leg,\n agencyBrandingUrl: leg.agency?.url,\n agencyId: leg.agency?.id,\n agencyName: leg.agency?.name,\n agencyUrl: leg.agency?.url,\n alightRule: pickupDropoffTypeToOtp1(leg.dropoffType),\n boardRule: pickupDropoffTypeToOtp1(leg.pickupType),\n bookingRuleInfo: {\n dropOff: leg?.dropOffBookingInfo || {},\n pickUp: leg?.pickupBookingInfo || {}\n },\n dropOffBookingInfo: {\n latestBookingTime: leg.dropOffBookingInfo\n },\n from: {\n ...leg.from,\n stopCode: leg.from.stop?.code,\n stopId: leg.from.stop?.gtfsId\n },\n route: leg.route?.shortName,\n routeColor: leg.route?.color,\n routeId: leg.route?.gtfsId,\n routeLongName: leg.route?.longName,\n routeShortName: leg.route?.shortName,\n routeTextColor: leg.route?.textColor,\n to: {\n ...leg.to,\n stopCode: leg.to.stop?.code,\n stopId: leg.to.stop?.gtfsId\n },\n tripHeadsign: leg.trip?.tripHeadsign,\n tripId: leg.trip?.gtfsId\n});\n\n/** Extracts the route number for a leg returned from OTP1 or OTP2. */\nexport const getLegRouteShortName = (\n leg: Pick<Leg, \"route\" | \"routeShortName\">\n): string | null => {\n const { route, routeShortName } = leg;\n // typeof route === \"object\" denotes newer OTP2 responses. routeShortName and route as string is OTP1.\n return typeof route === \"object\"\n ? route?.shortName\n : routeShortName || (route as string);\n};\n\n/** Extract the route long name for a leg returned from OTP1 or OTP2. */\nexport const getLegRouteLongName = (\n leg: Pick<Leg, \"route\" | \"routeLongName\">\n): string | null => {\n const { route, routeLongName } = leg;\n // typeof route === \"object\" denotes newer OTP2 responses. routeLongName is OTP1.\n return typeof route === \"object\" ? route?.longName : routeLongName;\n};\n\n/**\n * Returns the route short name, or the route long name if no short name is provided.\n * This is happens with Seattle area streetcars and ferries.\n */\nexport const getLegRouteName = (\n leg: Pick<Leg, \"route\" | \"routeLongName\" | \"routeShortName\">\n): string => {\n return getLegRouteShortName(leg) || getLegRouteLongName(leg);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAmBA,IAAAC,MAAA,GAAAF,sB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2R,KAAK;IAAEO;EAAe,CAAC,GAAGlS,GAAG;EACrC;EACA,OAAO,OAAO2R,KAAK,KAAK,QAAQ,GAC5BA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,SAAS,GAChBM,cAAc,IAAKP,KAAgB;AACzC,CAAC;;AAED;AAAAnS,OAAA,CAAAgT,oBAAA,GAAAA,oBAAA;AACO,MAAMC,mBAAmB,GAC9BzS,GAAyC,IACvB;EAClB,MAAM;IAAE2R,KAAK;IAAEK;EAAc,CAAC,GAAGhS,GAAG;EACpC;EACA,OAAO,OAAO2R,KAAK,KAAK,QAAQ,GAAGA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEM,QAAQ,GAAGD,aAAa;AACpE,CAAC;;AAED;AACA;AACA;AACA;AAHAxS,OAAA,CAAAiT,mBAAA,GAAAA,mBAAA;AAIO,MAAMC,eAAe,GAC1B1S,GAA4D,IACjD;EACX,OAAOwS,oBAAoB,CAACxS,GAAG,CAAC,IAAIyS,mBAAmB,CAACzS,GAAG,CAAC;AAC9D,CAAC;AAACR,OAAA,CAAAkT,eAAA,GAAAA,eAAA","ignoreList":[]}
1
+ {"version":3,"file":"itinerary.js","names":["_polyline","_interopRequireDefault","require","_along","transitModes","exports","getTransitModes","config","modes","map","tm","mode","isTransitLeg","leg","transitLeg","isTransit","includes","isReservationRequired","boardRule","alightRule","isCoordinationRequired","containsGeometry","place","_place$stop","_place$stop2","stop","geometries","undefined","endsWithGeometry","to","startsWithGeometry","from","legContainsGeometry","isAdvanceBookingRequired","info","_info$latestBookingTi","daysPrior","latestBookingTime","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isFlex","_leg$stopCalls","stopCalls","some","call","_call$stopLocation","stopLocation","__typename","startsWith","isRideshareLeg","_leg$rideHailingEstim","rideHailingEstimate","provider","id","isWalk","isBicycle","isBicycleRent","isCar","isMicromobility","isAccessMode","hasTransit","modesStr","split","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","_from$vehicleRentalSt","rentedBike","rentedCar","rentedVehicle","firstNetwork","Array","isArray","networks","length","rentalVehicle","network","vehicleRentalStation","rentalNetwork","networkId","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","polyline","toGeoJSON","legGeometry","points","coordinates","c","push","getLegBounds","lat","lon","legLocationAtDistance","distance","_pt$geometry","line","pt","turfAlong","units","geometry","legElevationAtDistance","elevation","reduce","acc","point","index","prevPoint","pointDistance","pointElevation","prevPointDistance","prevPointElevation","console","warn","mapOldElevationComponentToNew","oldElev","first","second","getElevationProfile","steps","unitConversion","minElev","maxElev","traversed","gain","loss","previous","step","_step$elevation","stepElevationProfile","elevationProfile","i","elev","diff","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","company","find","co","getCompaniesLabelFromNetworks","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","minPrice","maxPrice","currencyCode","currency","code","maxTNCFare","amount","minTNCFare","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","trolleybus","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","_itinerary$legs","carbonIntensityWithDefaults","totalCarbon","total","getDisplayedStopCode","placeOrStop","_placeOrStop$stopCode","stopCode","_placeOrStop$code","descope","item","substring","zeroDollars","getLegCost","mediumId","riderCategoryId","seenFareIds","fareProducts","price","relevantFareProducts","product","_product$riderCategor","_product$riderCategor2","_product$medium","_product$medium2","productRiderCategoryId","riderCategory","productMediaId","medium","fare","_fare$product","alreadySeen","legPrice","sort","a","b","_a$product","_b$product","cheapestRelevantFareProduct","alternateFareProducts","splice","fp","appliedFareProduct","isDependent","productUseId","getItineraryCost","nulledTotalFareOnAnyMissingFare","_total$currency","currentMediumId","_newCost$currency","newCost","digits","legCosts","_leg$fareProducts","seenIds","lc","l","prev","cur","pickupDropoffTypeToOtp1","otp2Type","convertGraphQLResponseToLegacy","_leg$agency","_leg$agency2","_leg$agency3","_leg$agency4","_leg$from$stop","_leg$from$stop2","_leg$route","_leg$route2","_leg$route3","_leg$route4","_leg$route5","_leg$route6","_leg$to$stop","_leg$to$stop2","_leg$trip","_leg$trip2","agencyBrandingUrl","agency","url","agencyId","agencyName","name","agencyUrl","dropoffType","pickupType","bookingRuleInfo","dropOff","pickUp","pickupBookingInfo","stopId","gtfsId","route","shortName","routeColor","color","routeId","routeLongName","longName","routeShortName","routeTextColor","textColor","tripHeadsign","trip","tripId","getLegRouteShortName","getLegRouteLongName","getLegRouteName"],"sources":["../src/itinerary.ts"],"sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n AppliedFareProduct,\n Company,\n Config,\n Currency,\n ElevationProfile,\n ElevationProfileComponent,\n FareProduct,\n FlexBookingInfo,\n ItineraryOnlyLegsRequired,\n LatLngArray,\n Leg,\n MassUnitOption,\n Money,\n Place,\n Step,\n Stop,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"TROLLEYBUS\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransitLeg(leg: Leg): boolean {\n return leg.transitLeg;\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg?.boardRule === \"mustPhone\" || leg?.alightRule === \"mustPhone\";\n}\n/**\n * Returns true if a user must ask the driver to let the user off\n * or if the user must flag the driver down for pickup.\n * \"coordinateWithDriver\" in board/alight rule encodes this info.\n */\nexport function isCoordinationRequired(leg: Leg): boolean {\n return (\n leg?.boardRule === \"coordinateWithDriver\" ||\n leg?.alightRule === \"coordinateWithDriver\"\n );\n}\n\nexport function containsGeometry(place: Place): boolean {\n return (\n place?.stop?.geometries !== null && place?.stop?.geometries !== undefined\n );\n}\nexport function endsWithGeometry(leg: Leg): boolean {\n return containsGeometry(leg?.to);\n}\nexport function startsWithGeometry(leg: Leg): boolean {\n return containsGeometry(leg?.from);\n}\nexport function legContainsGeometry(leg: Leg): boolean {\n return endsWithGeometry(leg) || startsWithGeometry(leg);\n}\nexport function isAdvanceBookingRequired(info?: FlexBookingInfo): boolean {\n const daysPrior = info?.latestBookingTime?.daysPrior;\n return typeof daysPrior === \"number\" && daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return (\n leg?.stopCalls?.some(call =>\n // Flex calls are \"Location\" or \"LocationGroup\"\n // eslint-disable-next-line no-underscore-dangle\n call?.stopLocation?.__typename.startsWith(\"Location\")\n ) || false\n );\n}\nexport function isRideshareLeg(leg: Leg): boolean {\n return !!leg.rideHailingEstimate?.provider?.id;\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n // @ts-expect-error this is not typed\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TROLLEYBUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg?: Leg): string | null {\n if (!leg) return null;\n const {\n from,\n mode,\n rentedBike,\n rentedCar,\n rentedVehicle,\n rideHailingEstimate\n } = leg;\n\n const firstNetwork =\n Array.isArray(from.networks) && from.networks.length > 0\n ? from.networks[0]\n : null;\n\n if (mode === \"CAR\" && rentedCar) {\n return firstNetwork;\n }\n if (mode === \"CAR\" && rideHailingEstimate) {\n return rideHailingEstimate.provider.id;\n }\n if (mode === \"BICYCLE\" && rentedBike) {\n return firstNetwork;\n }\n if (from.rentalVehicle) {\n return from.rentalVehicle.network;\n }\n if (from.vehicleRentalStation?.rentalNetwork) {\n return from.vehicleRentalStation.rentalNetwork.networkId;\n }\n if ((mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") && rentedVehicle) {\n return firstNetwork;\n }\n return null;\n}\n\nexport function getItineraryBounds(\n itinerary: ItineraryOnlyLegsRequired\n): LatLngArray[] {\n const coords: LatLngArray[] = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c): LatLngArray => [c[1], c[0]]);\n coords.push(...legCoords);\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[][] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\nexport function legLocationAtDistance(\n leg: Leg,\n distance: number\n): LatLngArray | undefined | null {\n if (!leg.legGeometry) return undefined;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n const coords = pt?.geometry?.coordinates;\n return [coords[1], coords[0]];\n } catch {\n // This is designed to catch the toGeoJSON from throwing if the geometry is not in the correct format\n }\n\n return null;\n}\n\n/**\n * Returns an interpolated elevation at a specified distance along a leg\n * @param points - The points of the elevation profile. Each point is a tuple of [distance, elevation].\n * @param distance - The distance along the leg to interpolate the elevation at\n * @returns The interpolated elevation at the specified distance\n */\n\nexport function legElevationAtDistance(\n points: [number, number][],\n distance: number\n): number | undefined {\n const elevation = points.reduce<number | undefined>((acc, point, index) => {\n const prevPoint = points[index - 1];\n // at the first index there is no previous point\n if (!prevPoint) return acc;\n const [pointDistance, pointElevation] = point;\n const [prevPointDistance, prevPointElevation] = prevPoint;\n if (distance >= prevPointDistance && distance <= pointDistance) {\n return (\n prevPointElevation +\n ((pointElevation - prevPointElevation) *\n (distance - prevPointDistance)) /\n (pointDistance - prevPointDistance)\n );\n }\n return acc;\n }, undefined);\n if (elevation === undefined) {\n console.warn(\"Elevation value does not exist for distance.\", distance);\n return undefined;\n }\n return elevation;\n}\n\nexport function mapOldElevationComponentToNew(oldElev: {\n first: number;\n second: number;\n}): ElevationProfileComponent {\n return {\n distance: oldElev.first,\n elevation: oldElev.second\n };\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous: ElevationProfileComponent | null = null;\n const points: [number, number][] = [];\n steps.forEach(step => {\n // Support for old REST response data (in step.elevation)\n const stepElevationProfile =\n step.elevationProfile ||\n (Array.isArray(step.elevation) &&\n step.elevation?.map<ElevationProfileComponent>(\n mapOldElevationComponentToNew\n ));\n\n if (!stepElevationProfile || stepElevationProfile.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < stepElevationProfile.length; i++) {\n const elev = stepElevationProfile[i];\n if (previous) {\n const diff = (elev.elevation - previous.elevation) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.distance !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.elevation * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.distance, elev.elevation]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (\n i === stepElevationProfile.length - 1 &&\n elev.distance !== step.distance\n ) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including reused canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // reuse canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n if (!context) return 0;\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company | undefined {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks. Returns\n * empty string if no networks provided.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks?: string[] | string,\n companies: Company[] = []\n): string {\n if (!networks) return \"\";\n return (Array.isArray(networks) ? networks : [networks])\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(\n leg: Pick<Leg, \"from\" | \"to\">,\n type: \"from\" | \"to\"\n): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: ItineraryOnlyLegsRequired\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(\n itinerary: ItineraryOnlyLegsRequired\n): TncFare {\n return itinerary.legs\n .filter(\n (\n leg\n ): leg is Leg & {\n rideHailingEstimate: NonNullable<Leg[\"rideHailingEstimate\"]>;\n } => leg.mode === \"CAR\" && leg.rideHailingEstimate !== undefined\n )\n .reduce<TncFare>(\n (acc, leg) => {\n const { minPrice, maxPrice } = leg.rideHailingEstimate;\n return {\n // Assumes a single currency for entire itinerary.\n currencyCode: minPrice.currency.code,\n maxTNCFare: acc.maxTNCFare + maxPrice.amount,\n minTNCFare: acc.minTNCFare + minPrice.amount\n };\n },\n {\n currencyCode: null,\n maxTNCFare: 0,\n minTNCFare: 0\n }\n );\n}\n\n/**\n * Sources:\n * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf\n * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey\n * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx\n * Other values extrapolated.\n */\nconst CARBON_INTENSITY_DEFAULTS: Record<string, number> = {\n walk: 0.026,\n bicycle: 0.017,\n car: 0.162,\n tram: 0.066,\n trolleybus: 0.066,\n subway: 0.066,\n rail: 0.066,\n bus: 0.09,\n ferry: 0.082,\n cable_car: 0.021,\n gondola: 0.021,\n funicular: 0.066,\n transit: 0.066,\n leg_switch: 0,\n airplane: 0.382,\n micromobility: 0.095\n};\n\n/**\n * @param {itinerary} itinerary OTP trip itinierary, only legs is required.\n * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter\n * @param {units} units units to be used in return value\n * @return Amount of carbon in chosen unit\n */\nexport function calculateEmissions(\n // This type makes all the properties from Itinerary optional except legs.\n itinerary: ItineraryOnlyLegsRequired,\n carbonIntensity: Record<string, number> = {},\n units?: MassUnitOption\n): number {\n // Apply defaults for any values that we don't have.\n const carbonIntensityWithDefaults = {\n ...CARBON_INTENSITY_DEFAULTS,\n ...carbonIntensity\n };\n\n // Distance is in meters, totalCarbon is in grams\n const totalCarbon =\n itinerary?.legs?.reduce((total, leg) => {\n return (\n (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||\n 0) + total\n );\n }, 0) || 0;\n\n switch (units) {\n case \"ounce\":\n return totalCarbon / 28.35;\n case \"kilogram\":\n return totalCarbon / 1000;\n case \"pound\":\n return totalCarbon / 454;\n case \"gram\":\n default:\n return totalCarbon;\n }\n}\n\n/**\n * Returns the user-facing stop code to display for a stop or place\n */\nexport function getDisplayedStopCode(\n placeOrStop: Place | Stop\n): string | undefined {\n if (\"stopId\" in placeOrStop) {\n return placeOrStop.stopCode ?? undefined;\n }\n if (\"id\" in placeOrStop) {\n return placeOrStop.code ?? undefined;\n }\n return undefined;\n}\n\n/**\n * Removes the first part of the OTP standard scope (\":\"), if it is present.\n * @param item String that is potentially scoped with `:` character\n * @returns descoped string\n */\nexport const descope = (item?: string | null): string | null | undefined => {\n if (!item) return item;\n const index = item.indexOf(\":\");\n return index === -1 ? item : item.substring(index + 1);\n};\n\nexport type ExtendedMoney = Money & { originalAmount?: number };\n\nexport const zeroDollars = (currency: Currency): Money => ({\n amount: 0,\n currency\n});\n\ntype FareProductWithPrice = FareProduct & { price: Money };\n\n/**\n * Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.\n * @param leg Leg with Fares v2 information\n * @param mediumId Desired medium ID to calculate fare for\n * @param riderCategoryId Desire rider category to calculate fare for\n * @param seenFareIds Fare IDs used on previous legs. Used to detect transfer discounts.\n * @returns Object containing price as well as transfer/dependent\n * fare information. `AppliedFareProduct` should contain\n * all the information needed, but the other fields are kept to\n * make the transition to Fares V2 less jarring.\n */\nexport function getLegCost(\n leg: Leg,\n mediumId?: string | null,\n riderCategoryId?: string | null,\n seenFareIds?: string[] | null\n): {\n alternateFareProducts?: AppliedFareProduct[];\n appliedFareProduct?: AppliedFareProduct;\n isDependent?: boolean;\n price?: Money;\n productUseId?: string;\n} {\n if (!leg.fareProducts) return { price: undefined };\n const relevantFareProducts = leg.fareProducts\n .filter(({ product }) => {\n // riderCategory and medium can be specifically defined as null to handle\n // generic GTFS based fares from OTP when there is no fare model\n\n // Remove (optional) agency scoping\n const productRiderCategoryId =\n descope(product?.riderCategory?.id) ||\n product?.riderCategory?.id ||\n null;\n\n const productMediaId =\n descope(product?.medium?.id) || product?.medium?.id || null;\n\n return (\n productRiderCategoryId === riderCategoryId &&\n productMediaId === mediumId &&\n // Make sure there's a price\n // Some fare products don't have a price at all.\n product?.price\n );\n })\n // Make sure there's a price\n // Some fare products don't have a price at all.\n .filter(\n (fare): fare is { id: string; product: FareProductWithPrice } =>\n fare.product?.price !== undefined\n )\n .map(fare => {\n const alreadySeen = !!seenFareIds && seenFareIds?.indexOf(fare.id) > -1;\n return {\n id: fare.id,\n product: {\n ...fare.product,\n legPrice:\n alreadySeen && fare.product.price\n ? zeroDollars(fare.product.price.currency)\n : fare.product.price\n } as AppliedFareProduct\n };\n })\n .sort((a, b) => a.product?.legPrice?.amount - b.product?.legPrice?.amount);\n\n // Return the cheapest, but include other matches as well\n const cheapestRelevantFareProduct = relevantFareProducts[0];\n\n // TODO: return one object here instead of dumbing it down?\n return {\n alternateFareProducts: relevantFareProducts.splice(1).map(fp => fp.product),\n appliedFareProduct: cheapestRelevantFareProduct?.product,\n isDependent:\n // eslint-disable-next-line no-underscore-dangle\n cheapestRelevantFareProduct?.product.__typename ===\n \"DependentFareProduct\",\n price: cheapestRelevantFareProduct?.product.legPrice,\n productUseId: cheapestRelevantFareProduct?.id\n };\n}\n\n/**\n * Returns the total itinerary cost for a given set of legs.\n * @param legs Itinerary legs with fare products (must have used getLegsWithFares)\n * @param category Rider category (youth, regular, senior)\n * @param container Fare container (cash, electronic)\n * @param seenFareIds List of fare product IDs that have already been seen on prev legs.\n * @param nulledTotalFareOnAnyMissingFare If this is set to true, the total fare\n * will be null if *any* fare is missing. If false, the total will be the total\n * fare with the missing fares ignored.\n * @returns Money object for the total itinerary cost.\n */\nexport function getItineraryCost(\n legs: Leg[],\n mediumId?: string | (string | null)[] | null,\n riderCategoryId?: string | (string | null)[] | null,\n nulledTotalFareOnAnyMissingFare = false\n): Money | undefined {\n if (Array.isArray(mediumId) || Array.isArray(riderCategoryId)) {\n // TODO: Better input type handling\n if (Array.isArray(mediumId) && Array.isArray(riderCategoryId)) {\n if (mediumId.length !== riderCategoryId.length) {\n console.warn(\n \"Invalid input types, only using first item. medium id list and rider category list must have same number of items\"\n );\n return getItineraryCost(legs, mediumId[0], riderCategoryId[0]);\n }\n\n const total = mediumId.reduce<Money>(\n (acc, currentMediumId, index) => {\n const newCost = getItineraryCost(\n legs,\n currentMediumId,\n riderCategoryId[index]\n );\n if (!newCost) return acc;\n\n return {\n amount: acc.amount + (newCost.amount || 0),\n currency:\n acc.currency.code !== \"\"\n ? acc.currency\n : newCost.currency ?? acc.currency\n };\n },\n { amount: 0, currency: { code: \"\", digits: 0 } }\n );\n\n if (!total.currency?.code) return undefined;\n return total;\n }\n console.warn(\n \"Invalid input types, only using first item. medium id list and rider category list must have same number of items\"\n );\n return undefined;\n }\n\n const legCosts = legs\n // Only legs with fares (no walking legs)\n .filter(leg => leg.fareProducts?.length && leg.fareProducts.length > 0)\n // Get the leg cost object of each leg\n .reduce<{ seenIds: string[]; legCosts: AppliedFareProduct[] }>(\n (acc, leg) => {\n // getLegCost handles filtering out duplicate use IDs\n // One fare product can be used on multiple legs,\n // and we don't want to count it more than once.\n // Use an object keyed by productUseId to deduplicate, then extract prices\n const { appliedFareProduct, productUseId } = getLegCost(\n leg,\n mediumId,\n riderCategoryId,\n acc.seenIds\n );\n if (!appliedFareProduct) return acc;\n if (!productUseId) return acc;\n return {\n legCosts: [...acc.legCosts, appliedFareProduct],\n seenIds: [...acc.seenIds, productUseId]\n };\n },\n { seenIds: [], legCosts: [] }\n )\n .legCosts.map(lc => lc.legPrice);\n\n if (\n nulledTotalFareOnAnyMissingFare &&\n legs.filter(l => l.transitLeg).length !== legCosts.length\n ) {\n return undefined;\n }\n\n if (legCosts.length === 0) return undefined;\n // Calculate the total\n return legCosts.reduce<Money>(\n (prev, cur) => ({\n amount: prev.amount + cur?.amount || 0,\n currency: prev.currency.code !== \"\" ? prev.currency : cur.currency\n }),\n // eslint-disable-next-line prettier/prettier -- old eslint doesn't know satisfies\n { amount: 0, currency: { code: \"\", digits: 0 } satisfies Currency }\n );\n}\n\nconst pickupDropoffTypeToOtp1 = (otp2Type: string): string | null => {\n switch (otp2Type) {\n case \"COORDINATE_WITH_DRIVER\":\n return \"coordinateWithDriver\";\n case \"CALL_AGENCY\":\n return \"mustPhone\";\n case \"SCHEDULED\":\n return \"scheduled\";\n case \"NONE\":\n return \"none\";\n default:\n return null;\n }\n};\n\nexport const convertGraphQLResponseToLegacy = (leg: any): Leg => ({\n ...leg,\n agencyBrandingUrl: leg.agency?.url,\n agencyId: leg.agency?.id,\n agencyName: leg.agency?.name,\n agencyUrl: leg.agency?.url,\n alightRule: pickupDropoffTypeToOtp1(leg.dropoffType),\n boardRule: pickupDropoffTypeToOtp1(leg.pickupType),\n bookingRuleInfo: {\n dropOff: leg?.dropOffBookingInfo || {},\n pickUp: leg?.pickupBookingInfo || {}\n },\n dropOffBookingInfo: {\n latestBookingTime: leg.dropOffBookingInfo\n },\n from: {\n ...leg.from,\n stopCode: leg.from.stop?.code,\n stopId: leg.from.stop?.gtfsId\n },\n route: leg.route?.shortName,\n routeColor: leg.route?.color,\n routeId: leg.route?.gtfsId,\n routeLongName: leg.route?.longName,\n routeShortName: leg.route?.shortName,\n routeTextColor: leg.route?.textColor,\n to: {\n ...leg.to,\n stopCode: leg.to.stop?.code,\n stopId: leg.to.stop?.gtfsId\n },\n tripHeadsign: leg.trip?.tripHeadsign,\n tripId: leg.trip?.gtfsId\n});\n\n/** Extracts the route number for a leg returned from OTP1 or OTP2. */\nexport const getLegRouteShortName = (\n leg: Pick<Leg, \"route\" | \"routeShortName\">\n): string | null => {\n const { route, routeShortName } = leg;\n // typeof route === \"object\" denotes newer OTP2 responses. routeShortName and route as string is OTP1.\n return typeof route === \"object\"\n ? route?.shortName\n : routeShortName || (route as string);\n};\n\n/** Extract the route long name for a leg returned from OTP1 or OTP2. */\nexport const getLegRouteLongName = (\n leg: Pick<Leg, \"route\" | \"routeLongName\">\n): string | undefined => {\n const { route, routeLongName } = leg;\n // typeof route === \"object\" denotes newer OTP2 responses. routeLongName is OTP1.\n return typeof route === \"object\" ? route?.longName : routeLongName;\n};\n\n/**\n * Returns the route short name, or the route long name if no short name is provided.\n * This is happens with Seattle area streetcars and ferries.\n */\nexport const getLegRouteName = (\n leg: Pick<Leg, \"route\" | \"routeLongName\" | \"routeShortName\">\n): string | undefined => {\n return getLegRouteShortName(leg) || getLegRouteLongName(leg);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAoBA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA;AACO,MAAME,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,CAC1B,MAAM,EACN,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,OAAO,EACP,MAAM,EACN,SAAS,CACV;;AAED;AACA;AACA;AACA;;AAEO,SAASE,eAAeA,CAACC,MAAc,EAAY;EACxD,IAAI,CAACA,MAAM,IAAI,CAACA,MAAM,CAACC,KAAK,IAAI,CAACD,MAAM,CAACC,KAAK,CAACJ,YAAY,EACxD,OAAOA,YAAY;EAErB,OAAOG,MAAM,CAACC,KAAK,CAACJ,YAAY,CAACK,GAAG,CAACC,EAAE,IACrC,OAAOA,EAAE,KAAK,QAAQ,GAAGA,EAAE,CAACC,IAAI,GAAGD,EACrC,CAAC;AACH;AAEO,SAASE,YAAYA,CAACC,GAAQ,EAAW;EAC9C,OAAOA,GAAG,CAACC,UAAU;AACvB;AAEO,SAASC,SAASA,CAACJ,IAAY,EAAW;EAC/C,OAAOP,YAAY,CAACY,QAAQ,CAACL,IAAI,CAAC,IAAIA,IAAI,KAAK,SAAS;AAC1D;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASM,qBAAqBA,CAACJ,GAAQ,EAAW;EACvD,OAAO,CAAAA,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEK,SAAS,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iS,KAAK;IAAEK;EAAc,CAAC,GAAGtS,GAAG;EACpC;EACA,OAAO,OAAOiS,KAAK,KAAK,QAAQ,GAAGA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEM,QAAQ,GAAGD,aAAa;AACpE,CAAC;;AAED;AACA;AACA;AACA;AAHA9S,OAAA,CAAAuT,mBAAA,GAAAA,mBAAA;AAIO,MAAMC,eAAe,GAC1BhT,GAA4D,IACrC;EACvB,OAAO8S,oBAAoB,CAAC9S,GAAG,CAAC,IAAI+S,mBAAmB,CAAC/S,GAAG,CAAC;AAC9D,CAAC;AAACR,OAAA,CAAAwT,eAAA,GAAAA,eAAA","ignoreList":[]}
package/lib/map.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LatLngArray, Location, UserPosition } from "@opentripplanner/types";
2
- export declare function currentPositionToLocation(currentPosition: UserPosition): Location;
3
- export declare function coordsToString(coords: number[]): string;
2
+ export declare function currentPositionToLocation(currentPosition: UserPosition): Location | null;
3
+ export declare function coordsToString(coords: number[]): string | undefined;
4
4
  export declare function stringToCoords(str: string): number[];
5
5
  export declare function constructLocation(latlng: {
6
6
  lat: number;
package/lib/map.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE7E,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,YAAY,GAC5B,QAAQ,CAYV;AAID,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAEvD;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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AkB,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
@@ -29,7 +29,7 @@ function currentPositionToLocation(currentPosition) {
29
29
  // TRICKY: This method is used in query.js and in the context of
30
30
  // otp-rr actions where the intl context is not available/does not apply.
31
31
  function coordsToString(coords) {
32
- return coords.length && coords.map(c => (+c).toFixed(5)).join(", ");
32
+ return coords.length > 0 ? coords.map(c => (+c).toFixed(5)).join(", ") : undefined;
33
33
  }
34
34
  function stringToCoords(str) {
35
35
  return str && str.split(",").map(c => +c) || [];