@opentripplanner/core-utils 4.11.4 → 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 (81) hide show
  1. package/esm/deprecated-with-types.js +47 -0
  2. package/esm/deprecated-with-types.js.map +1 -0
  3. package/esm/deprecated.js +7 -0
  4. package/esm/deprecated.js.map +1 -1
  5. package/esm/index.js +0 -4
  6. package/esm/index.js.map +1 -1
  7. package/esm/itinerary.js +3 -9
  8. package/esm/itinerary.js.map +1 -1
  9. package/esm/map.js +2 -1
  10. package/esm/map.js.map +1 -1
  11. package/esm/query-params.js +5 -12
  12. package/esm/query-params.js.map +1 -1
  13. package/esm/route.js +5 -3
  14. package/esm/route.js.map +1 -1
  15. package/esm/storage.js +1 -0
  16. package/esm/storage.js.map +1 -1
  17. package/esm/time.js +6 -36
  18. package/esm/time.js.map +1 -1
  19. package/esm/ui.js +1 -1
  20. package/esm/ui.js.map +1 -1
  21. package/lib/deprecated-with-types.d.ts +23 -0
  22. package/lib/deprecated-with-types.d.ts.map +1 -0
  23. package/lib/deprecated-with-types.js +61 -0
  24. package/lib/deprecated-with-types.js.map +1 -0
  25. package/lib/deprecated.js +9 -0
  26. package/lib/deprecated.js.map +1 -1
  27. package/lib/index.d.ts +19 -0
  28. package/lib/index.d.ts.map +1 -0
  29. package/lib/index.js +0 -6
  30. package/lib/index.js.map +1 -1
  31. package/lib/itinerary.d.ts +113 -0
  32. package/lib/itinerary.d.ts.map +1 -0
  33. package/lib/itinerary.js +8 -9
  34. package/lib/itinerary.js.map +1 -1
  35. package/lib/map.d.ts +30 -0
  36. package/lib/map.d.ts.map +1 -0
  37. package/lib/map.js +1 -0
  38. package/lib/map.js.map +1 -1
  39. package/lib/query-params.js +4 -11
  40. package/lib/query-params.js.map +1 -1
  41. package/lib/route.d.ts +98 -0
  42. package/lib/route.d.ts.map +1 -0
  43. package/lib/route.js +5 -3
  44. package/lib/route.js.map +1 -1
  45. package/lib/storage.d.ts +19 -0
  46. package/lib/storage.d.ts.map +1 -0
  47. package/lib/storage.js +2 -0
  48. package/lib/storage.js.map +1 -1
  49. package/lib/time.d.ts +65 -0
  50. package/lib/time.d.ts.map +1 -0
  51. package/lib/time.js +22 -39
  52. package/lib/time.js.map +1 -1
  53. package/lib/ui.d.ts +13 -0
  54. package/lib/ui.d.ts.map +1 -0
  55. package/lib/ui.js +1 -1
  56. package/lib/ui.js.map +1 -1
  57. package/package.json +4 -1
  58. package/src/__tests__/__snapshots__/query.js.snap +0 -8
  59. package/src/__tests__/__snapshots__/route.js.snap +30 -30
  60. package/src/deprecated-with-types.ts +62 -0
  61. package/src/deprecated.js +16 -0
  62. package/src/{index.js → index.ts} +0 -4
  63. package/src/{itinerary.js → itinerary.ts} +72 -50
  64. package/src/{map.js → map.ts} +41 -20
  65. package/src/query-params.js +3 -11
  66. package/src/{route.js → route.ts} +52 -28
  67. package/src/{storage.js → storage.ts} +6 -5
  68. package/src/{time.js → time.ts} +28 -46
  69. package/src/{ui.js → ui.ts} +8 -8
  70. package/tsconfig.json +15 -0
  71. package/tsconfig.tsbuildinfo +4921 -0
  72. package/esm/messages.js +0 -25
  73. package/esm/messages.js.map +0 -1
  74. package/esm/types.js +0 -560
  75. package/esm/types.js.map +0 -1
  76. package/lib/messages.js +0 -29
  77. package/lib/messages.js.map +0 -1
  78. package/lib/types.js +0 -661
  79. package/lib/types.js.map +0 -1
  80. package/src/messages.js +0 -20
  81. package/src/types.js +0 -605
@@ -0,0 +1,62 @@
1
+ /* eslint-disable import/no-cycle */
2
+ import { TimeOptions } from "@opentripplanner/types";
3
+ import { format } from "date-fns";
4
+
5
+ import { logDeprecationWarning } from "./deprecated";
6
+ import {
7
+ formatDurationLikeMoment,
8
+ offsetTime,
9
+ OTP_API_TIME_FORMAT
10
+ } from "./time";
11
+
12
+ // time.ts
13
+
14
+ /**
15
+ * Formats a time value for display in narrative
16
+ * TODO: internationalization/timezone
17
+ * @param {number} ms epoch time value in milliseconds
18
+ * @returns {string} formatted text representation
19
+ */
20
+ export function formatTime(ms: number, options: TimeOptions): string {
21
+ logDeprecationWarning("formatTime", "formatjs");
22
+
23
+ return format(
24
+ offsetTime(ms, options),
25
+ options?.format || OTP_API_TIME_FORMAT
26
+ );
27
+ }
28
+
29
+ /**
30
+ * Formats an elapsed time duration for display in narrative.
31
+ * TODO: internationalization
32
+ * @param {number} seconds duration in seconds
33
+ * @returns {string} formatted text representation
34
+ */
35
+ // TS TODO: region as type?
36
+ export function formatDuration(seconds: number, region: string): string {
37
+ logDeprecationWarning("formatDuration", "formatjs");
38
+
39
+ return formatDurationLikeMoment(seconds, false, {
40
+ enabled: true,
41
+ code: region
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Formats an elapsed time in seconds, minutes, hours duration for display in narrative
47
+ * @param {number} seconds duration in seconds
48
+ * @param {object} region an object that allows internationalization of the time
49
+ * @returns {string} formatted text representation
50
+ */
51
+ // TS TODO: region as type?
52
+ export function formatDurationWithSeconds(
53
+ seconds: number,
54
+ region: string
55
+ ): string {
56
+ logDeprecationWarning("formatDurationWithSeconds", "formatjs");
57
+
58
+ return formatDurationLikeMoment(seconds, true, {
59
+ enabled: true,
60
+ code: region
61
+ });
62
+ }
package/src/deprecated.js CHANGED
@@ -316,3 +316,19 @@ export function summarizeQuery(query, locations = []) {
316
316
  : require("./itinerary").toSentenceCase(query.mode);
317
317
  return `${mode} from ${from} to ${to}`;
318
318
  }
319
+
320
+ export function getTimeZoneOffset(itinerary) {
321
+ logDeprecationWarning("getTimeZoneOffset");
322
+
323
+ if (!itinerary.legs || !itinerary.legs.length) return 0;
324
+
325
+ // Determine if there is a DST offset between now and the itinerary start date
326
+ const dstOffset =
327
+ new Date(itinerary.startTime).getTimezoneOffset() -
328
+ new Date().getTimezoneOffset();
329
+
330
+ return (
331
+ itinerary.legs[0].agencyTimeZoneOffset +
332
+ (new Date().getTimezoneOffset() + dstOffset) * 60000
333
+ );
334
+ }
@@ -1,26 +1,22 @@
1
1
  import * as itinerary from "./itinerary";
2
2
  import * as map from "./map";
3
- import * as messages from "./messages";
4
3
  import * as profile from "./profile";
5
4
  import * as query from "./query";
6
5
  import * as queryParams from "./query-params";
7
6
  import * as route from "./route";
8
7
  import * as storage from "./storage";
9
8
  import * as time from "./time";
10
- import * as types from "./types";
11
9
  import * as ui from "./ui";
12
10
 
13
11
  const core = {
14
12
  itinerary,
15
13
  map,
16
- messages,
17
14
  profile,
18
15
  query,
19
16
  queryParams,
20
17
  route,
21
18
  storage,
22
19
  time,
23
- types,
24
20
  ui
25
21
  };
26
22
 
@@ -1,4 +1,14 @@
1
1
  import polyline from "@mapbox/polyline";
2
+ import {
3
+ Company,
4
+ Config,
5
+ ElevationProfile,
6
+ FlexBookingInfo,
7
+ Itinerary,
8
+ LatLngArray,
9
+ Leg,
10
+ Step
11
+ } from "@opentripplanner/types";
2
12
  import turfAlong from "@turf/along";
3
13
 
4
14
  import {
@@ -9,6 +19,7 @@ import {
9
19
  getStepDirection,
10
20
  getStepInstructions,
11
21
  getStepStreetName,
22
+ getTimeZoneOffset,
12
23
  getTransitFare
13
24
  } from "./deprecated";
14
25
 
@@ -20,6 +31,7 @@ export {
20
31
  getStepDirection,
21
32
  getStepInstructions,
22
33
  getStepStreetName,
34
+ getTimeZoneOffset,
23
35
  getTransitFare
24
36
  };
25
37
 
@@ -38,13 +50,16 @@ export const transitModes = [
38
50
  * @return {Array} List of all transit modes defined in config; otherwise default mode list
39
51
  */
40
52
 
41
- export function getTransitModes(config) {
53
+ export function getTransitModes(config: Config): string[] {
42
54
  if (!config || !config.modes || !config.modes.transitModes)
43
55
  return transitModes;
44
- return config.modes.transitModes.map(tm => tm.mode);
56
+
57
+ return config.modes.transitModes.map(tm =>
58
+ typeof tm !== "string" ? tm.mode : tm
59
+ );
45
60
  }
46
61
 
47
- export function isTransit(mode) {
62
+ export function isTransit(mode: string): boolean {
48
63
  return transitModes.includes(mode) || mode === "TRANSIT";
49
64
  }
50
65
 
@@ -53,7 +68,7 @@ export function isTransit(mode) {
53
68
  * calling ahead for the service to run. "mustPhone" is the only
54
69
  * property of boardRule which encodes this info.
55
70
  */
56
- export function isReservationRequired(leg) {
71
+ export function isReservationRequired(leg: Leg): boolean {
57
72
  return leg.boardRule === "mustPhone";
58
73
  }
59
74
  /**
@@ -61,53 +76,53 @@ export function isReservationRequired(leg) {
61
76
  * asking the driver to let the user off. "coordinateWithDriver" is the only
62
77
  * property of alightRule which encodes this info.
63
78
  */
64
- export function isContinuousDropoff(leg) {
79
+ export function isContinuousDropoff(leg: Leg): boolean {
65
80
  return leg.alightRule === "coordinateWithDriver";
66
81
  }
67
82
  /**
68
83
  * The two rules checked by the above two functions are the only values
69
84
  * returned by OTP when a leg is a flex leg.
70
85
  */
71
- export function isFlex(leg) {
86
+ export function isFlex(leg: Leg): boolean {
72
87
  return isReservationRequired(leg) || isContinuousDropoff(leg);
73
88
  }
74
89
 
75
- export function isAdvanceBookingRequired(info) {
90
+ export function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {
76
91
  return info?.latestBookingTime?.daysPrior > 0;
77
92
  }
78
- export function legDropoffRequiresAdvanceBooking(leg) {
93
+ export function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {
79
94
  return isAdvanceBookingRequired(leg.dropOffBookingInfo);
80
95
  }
81
96
 
82
- export function isWalk(mode) {
97
+ export function isWalk(mode: string): boolean {
83
98
  if (!mode) return false;
84
99
 
85
100
  return mode === "WALK";
86
101
  }
87
102
 
88
- export function isBicycle(mode) {
103
+ export function isBicycle(mode: string): boolean {
89
104
  if (!mode) return false;
90
105
 
91
106
  return mode === "BICYCLE";
92
107
  }
93
108
 
94
- export function isBicycleRent(mode) {
109
+ export function isBicycleRent(mode: string): boolean {
95
110
  if (!mode) return false;
96
111
 
97
112
  return mode === "BICYCLE_RENT";
98
113
  }
99
114
 
100
- export function isCar(mode) {
115
+ export function isCar(mode: string): boolean {
101
116
  if (!mode) return false;
102
117
  return mode.startsWith("CAR");
103
118
  }
104
119
 
105
- export function isMicromobility(mode) {
120
+ export function isMicromobility(mode: string): boolean {
106
121
  if (!mode) return false;
107
122
  return mode.startsWith("MICROMOBILITY") || mode.startsWith("SCOOTER");
108
123
  }
109
124
 
110
- export function isAccessMode(mode) {
125
+ export function isAccessMode(mode: string): boolean {
111
126
  return (
112
127
  isWalk(mode) ||
113
128
  isBicycle(mode) ||
@@ -121,7 +136,7 @@ export function isAccessMode(mode) {
121
136
  * @param {string} modesStr a comma-separated list of OTP modes
122
137
  * @return {boolean} whether any of the modes are transit modes
123
138
  */
124
- export function hasTransit(modesStr) {
139
+ export function hasTransit(modesStr: string): boolean {
125
140
  return modesStr.split(",").some(mode => isTransit(mode));
126
141
  }
127
142
 
@@ -129,7 +144,7 @@ export function hasTransit(modesStr) {
129
144
  * @param {string} modesStr a comma-separated list of OTP modes
130
145
  * @return {boolean} whether any of the modes are car-based modes
131
146
  */
132
- export function hasCar(modesStr) {
147
+ export function hasCar(modesStr: string): boolean {
133
148
  return modesStr.split(",").some(mode => isCar(mode));
134
149
  }
135
150
 
@@ -137,7 +152,7 @@ export function hasCar(modesStr) {
137
152
  * @param {string} modesStr a comma-separated list of OTP modes
138
153
  * @return {boolean} whether any of the modes are bicycle-based modes
139
154
  */
140
- export function hasBike(modesStr) {
155
+ export function hasBike(modesStr: string): boolean {
141
156
  return modesStr
142
157
  .split(",")
143
158
  .some(mode => isBicycle(mode) || isBicycleRent(mode));
@@ -147,7 +162,7 @@ export function hasBike(modesStr) {
147
162
  * @param {string} modesStr a comma-separated list of OTP modes
148
163
  * @return {boolean} whether any of the modes are micromobility-based modes
149
164
  */
150
- export function hasMicromobility(modesStr) {
165
+ export function hasMicromobility(modesStr: string): boolean {
151
166
  return modesStr.split(",").some(mode => isMicromobility(mode));
152
167
  }
153
168
 
@@ -155,7 +170,7 @@ export function hasMicromobility(modesStr) {
155
170
  * @param {string} modesStr a comma-separated list of OTP modes
156
171
  * @return {boolean} whether any of the modes is a hailing mode
157
172
  */
158
- export function hasHail(modesStr) {
173
+ export function hasHail(modesStr: string): boolean {
159
174
  return modesStr.split(",").some(mode => mode.indexOf("_HAIL") > -1);
160
175
  }
161
176
 
@@ -163,11 +178,11 @@ export function hasHail(modesStr) {
163
178
  * @param {string} modesStr a comma-separated list of OTP modes
164
179
  * @return {boolean} whether any of the modes is a rental mode
165
180
  */
166
- export function hasRental(modesStr) {
181
+ export function hasRental(modesStr: string): boolean {
167
182
  return modesStr.split(",").some(mode => mode.indexOf("_RENT") > -1);
168
183
  }
169
184
 
170
- export function getMapColor(mode) {
185
+ export function getMapColor(mode: string): string {
171
186
  mode = mode || this.get("mode");
172
187
  if (mode === "WALK") return "#444";
173
188
  if (mode === "BICYCLE") return "#0073e5";
@@ -181,7 +196,7 @@ export function getMapColor(mode) {
181
196
  return "#aaa";
182
197
  }
183
198
 
184
- export function toSentenceCase(str) {
199
+ export function toSentenceCase(str: string): string {
185
200
  if (str == null) {
186
201
  return "";
187
202
  }
@@ -192,7 +207,7 @@ export function toSentenceCase(str) {
192
207
  /**
193
208
  * Derive the company string based on mode and network associated with leg.
194
209
  */
195
- export function getCompanyFromLeg(leg) {
210
+ export function getCompanyFromLeg(leg: Leg): string {
196
211
  if (!leg) return null;
197
212
  const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;
198
213
  if (mode === "CAR" && rentedCar) {
@@ -214,12 +229,12 @@ export function getCompanyFromLeg(leg) {
214
229
  return null;
215
230
  }
216
231
 
217
- export function getItineraryBounds(itinerary) {
232
+ export function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {
218
233
  let coords = [];
219
234
  itinerary.legs.forEach(leg => {
220
235
  const legCoords = polyline
221
236
  .toGeoJSON(leg.legGeometry.points)
222
- .coordinates.map(c => [c[1], c[0]]);
237
+ .coordinates.map((c: number[]) => [c[1], c[0]]);
223
238
  coords = [...coords, ...legCoords];
224
239
  });
225
240
  return coords;
@@ -228,7 +243,7 @@ export function getItineraryBounds(itinerary) {
228
243
  /**
229
244
  * Return a coords object that encloses the given leg's geometry.
230
245
  */
231
- export function getLegBounds(leg) {
246
+ export function getLegBounds(leg: Leg): number[] {
232
247
  const coords = polyline
233
248
  .toGeoJSON(leg.legGeometry.points)
234
249
  .coordinates.map(c => [c[1], c[0]]);
@@ -244,7 +259,7 @@ export function getLegBounds(leg) {
244
259
 
245
260
  /* Returns an interpolated lat-lon at a specified distance along a leg */
246
261
 
247
- export function legLocationAtDistance(leg, distance) {
262
+ export function legLocationAtDistance(leg: Leg, distance: number): number[] {
248
263
  if (!leg.legGeometry) return null;
249
264
 
250
265
  try {
@@ -262,7 +277,10 @@ export function legLocationAtDistance(leg, distance) {
262
277
 
263
278
  /* Returns an interpolated elevation at a specified distance along a leg */
264
279
 
265
- export function legElevationAtDistance(points, distance) {
280
+ export function legElevationAtDistance(
281
+ points: number[][],
282
+ distance: number
283
+ ): number {
266
284
  // Iterate through the combined elevation profile
267
285
  let traversed = 0;
268
286
  // If first point distance is not zero, insert starting point at zero with
@@ -300,7 +318,10 @@ export function legElevationAtDistance(points, distance) {
300
318
 
301
319
  // Iterate through the steps, building the array of elevation points and
302
320
  // keeping track of the minimum and maximum elevations reached
303
- export function getElevationProfile(steps, unitConversion = 1) {
321
+ export function getElevationProfile(
322
+ steps: Step[],
323
+ unitConversion = 1
324
+ ): ElevationProfile {
304
325
  let minElev = 100000;
305
326
  let maxElev = -100000;
306
327
  let traversed = 0;
@@ -347,11 +368,14 @@ export function getElevationProfile(steps, unitConversion = 1) {
347
368
  *
348
369
  * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
349
370
  */
350
- export function getTextWidth(text, font = "22px Arial") {
371
+ export function getTextWidth(text: string, font = "22px Arial"): number {
372
+ // Create custom type for function including re-used canvas object
373
+ type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };
374
+
351
375
  // re-use canvas object for better performance
352
376
  const canvas =
353
- getTextWidth.canvas ||
354
- (getTextWidth.canvas = document.createElement("canvas"));
377
+ (getTextWidth as GetTextWidth).canvas ||
378
+ ((getTextWidth as GetTextWidth).canvas = document.createElement("canvas"));
355
379
  const context = canvas.getContext("2d");
356
380
  context.font = font;
357
381
  const metrics = context.measureText(text);
@@ -362,7 +386,10 @@ export function getTextWidth(text, font = "22px Arial") {
362
386
  * Get the configured company object for the given network string if the company
363
387
  * has been defined in the provided companies array config.
364
388
  */
365
- export function getCompanyForNetwork(networkString, companies = []) {
389
+ export function getCompanyForNetwork(
390
+ networkString: string,
391
+ companies: Company[] = []
392
+ ): Company {
366
393
  const company = companies.find(co => co.id === networkString);
367
394
  if (!company) {
368
395
  console.warn(
@@ -380,7 +407,10 @@ export function getCompanyForNetwork(networkString, companies = []) {
380
407
  * @param {Array<object>} [companies=[]] An optional list of the companies config.
381
408
  * @return {string} A label for use in presentation on a website.
382
409
  */
383
- export function getCompaniesLabelFromNetworks(networks, companies = []) {
410
+ export function getCompaniesLabelFromNetworks(
411
+ networks: string[],
412
+ companies: Company[] = []
413
+ ): string {
384
414
  return networks
385
415
  .map(network => getCompanyForNetwork(network, companies))
386
416
  .filter(co => !!co)
@@ -388,12 +418,18 @@ export function getCompaniesLabelFromNetworks(networks, companies = []) {
388
418
  .join("/");
389
419
  }
390
420
 
391
- export function getTNCLocation(leg, type) {
421
+ export function getTNCLocation(leg: Leg, type: string): string {
392
422
  const location = leg[type];
393
423
  return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;
394
424
  }
395
425
 
396
- export function calculatePhysicalActivity(itinerary) {
426
+ export function calculatePhysicalActivity(
427
+ itinerary: Itinerary
428
+ ): {
429
+ bikeDuration: number;
430
+ caloriesBurned: number;
431
+ walkDuration: number;
432
+ } {
397
433
  let walkDuration = 0;
398
434
  let bikeDuration = 0;
399
435
  itinerary.legs.forEach(leg => {
@@ -409,20 +445,6 @@ export function calculatePhysicalActivity(itinerary) {
409
445
  };
410
446
  }
411
447
 
412
- export function getTimeZoneOffset(itinerary) {
413
- if (!itinerary.legs || !itinerary.legs.length) return 0;
414
-
415
- // Determine if there is a DST offset between now and the itinerary start date
416
- const dstOffset =
417
- new Date(itinerary.startTime).getTimezoneOffset() -
418
- new Date().getTimezoneOffset();
419
-
420
- return (
421
- itinerary.legs[0].agencyTimeZoneOffset +
422
- (new Date().getTimezoneOffset() + dstOffset) * 60000
423
- );
424
- }
425
-
426
448
  export function calculateTncFares(itinerary) {
427
449
  // TODO: don't rely on deprecated methods!
428
450
  // At the moment this is safe as none of these exported variables contain strings
@@ -1,9 +1,18 @@
1
+ import {
2
+ Company,
3
+ Itinerary,
4
+ LatLngArray,
5
+ Leg,
6
+ Location,
7
+ TransitiveData,
8
+ UserPosition
9
+ } from "@opentripplanner/types";
1
10
  import {
2
11
  getPlaceName,
3
- isTransit,
12
+ isAccessMode,
4
13
  isFlex,
5
- toSentenceCase,
6
- isAccessMode
14
+ isTransit,
15
+ toSentenceCase
7
16
  } from "./itinerary";
8
17
 
9
18
  import {
@@ -15,7 +24,9 @@ import {
15
24
 
16
25
  export { coordsToString, getDetailText, latlngToString };
17
26
 
18
- export function currentPositionToLocation(currentPosition) {
27
+ export function currentPositionToLocation(
28
+ currentPosition: UserPosition
29
+ ): Location {
19
30
  if (currentPosition.error || !currentPosition.coords) {
20
31
  console.warn(
21
32
  "Cannot construct location from current position due to geolocation error or missing coordinates."
@@ -29,18 +40,24 @@ export function currentPositionToLocation(currentPosition) {
29
40
  };
30
41
  }
31
42
 
32
- export function stringToCoords(str) {
43
+ export function stringToCoords(str: string): number[] {
33
44
  return (str && str.split(",").map(c => +c)) || [];
34
45
  }
35
46
 
36
- export function constructLocation(latlng) {
47
+ export function constructLocation(latlng: {
48
+ lat: number;
49
+ lng: number;
50
+ }): Location {
37
51
  return {
38
52
  lat: latlng.lat,
39
53
  lon: latlng.lng
40
54
  };
41
55
  }
42
56
 
43
- export function formatStoredPlaceName(location, withDetails = true) {
57
+ export function formatStoredPlaceName(
58
+ location: Location,
59
+ withDetails = true
60
+ ): string {
44
61
  if (withDetails) {
45
62
  logDeprecationWarning("the formatStoredPlaceName withDetails parameter");
46
63
  }
@@ -56,7 +73,7 @@ export function formatStoredPlaceName(location, withDetails = true) {
56
73
  return displayName;
57
74
  }
58
75
 
59
- export function matchLatLon(location1, location2) {
76
+ export function matchLatLon(location1: Location, location2: Location): boolean {
60
77
  if (!location1 || !location2) return location1 === location2;
61
78
  return location1.lat === location2.lat && location1.lon === location2.lon;
62
79
  }
@@ -70,11 +87,11 @@ export function matchLatLon(location1, location2) {
70
87
  * @returns An itinerary in the transitive.js format.
71
88
  */
72
89
  export function itineraryToTransitive(
73
- itin,
74
- companies,
75
- getRouteLabel,
76
- disableFlexArc
77
- ) {
90
+ itin: Itinerary,
91
+ companies: Company[],
92
+ getRouteLabel: (leg: Leg) => string,
93
+ disableFlexArc: boolean
94
+ ): TransitiveData {
78
95
  const tdata = {
79
96
  journeys: [],
80
97
  streetEdges: [],
@@ -109,7 +126,7 @@ export function itineraryToTransitive(
109
126
 
110
127
  itin.legs.forEach((leg, idx) => {
111
128
  if (isAccessMode(leg.mode)) {
112
- let fromPlaceId;
129
+ let fromPlaceId: string;
113
130
  if (leg.from.bikeShareId) {
114
131
  fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;
115
132
  // TODO: does this need to change to be OTP2 compatible?
@@ -143,6 +160,7 @@ export function itineraryToTransitive(
143
160
  }
144
161
 
145
162
  const segment = {
163
+ arc: false,
146
164
  type: leg.mode,
147
165
  streetEdges: [streetEdgeId],
148
166
  from: { type: "PLACE", place_id: fromPlaceId },
@@ -298,27 +316,30 @@ export function itineraryToTransitive(
298
316
  return tdata;
299
317
  }
300
318
 
301
- export function isBikeshareStation(place) {
319
+ type TransitivePlaceRaw = {
320
+ place_id: string;
321
+ };
322
+ export function isBikeshareStation(place: TransitivePlaceRaw): boolean {
302
323
  return place.place_id.lastIndexOf("bicycle_rent_station") !== -1;
303
324
  }
304
325
 
305
- export function isEScooterStation(place) {
326
+ export function isEScooterStation(place: TransitivePlaceRaw): boolean {
306
327
  return place.place_id.lastIndexOf("escooter_rent_station") !== -1;
307
328
  }
308
329
 
309
- export function isCarWalkTransition(place) {
330
+ export function isCarWalkTransition(place: TransitivePlaceRaw): boolean {
310
331
  return place.place_id.lastIndexOf("itin_car_") !== -1;
311
332
  }
312
333
 
313
- export function isValidLat(lat) {
334
+ export function isValidLat(lat: number): boolean {
314
335
  return Number.isFinite(lat) && lat >= -90 && lat <= 90;
315
336
  }
316
337
 
317
- export function isValidLng(lng) {
338
+ export function isValidLng(lng: number): boolean {
318
339
  return Number.isFinite(lng) && lng >= -180 && lng <= 180;
319
340
  }
320
341
 
321
- export function isValidLatLng(arr) {
342
+ export function isValidLatLng(arr: LatLngArray): boolean {
322
343
  return (
323
344
  Array.isArray(arr) &&
324
345
  arr.length === 2 &&
@@ -278,8 +278,8 @@ const queryParams = [
278
278
  {
279
279
  /* optimize -- how to optimize a trip (non-bike, non-micromobility trips) */
280
280
  name: "optimize",
281
- applicable: query =>
282
- !query.otp2 && hasTransit(query.mode) && !hasBike(query.mode),
281
+ // This parameter doesn't seem to do anything
282
+ applicable: () => false,
283
283
  routingTypes: ["ITINERARY"],
284
284
  default: "QUICK",
285
285
  selector: "DROPDOWN",
@@ -304,7 +304,7 @@ const queryParams = [
304
304
  default: "SAFE",
305
305
  selector: "DROPDOWN",
306
306
  label: "Optimize for",
307
- options: query => {
307
+ options: () => {
308
308
  const opts = [
309
309
  {
310
310
  text: "Speed",
@@ -320,14 +320,6 @@ const queryParams = [
320
320
  }
321
321
  ];
322
322
 
323
- // Include transit-specific option, if applicable
324
- if (hasTransit(query.mode)) {
325
- opts.splice(1, 0, {
326
- text: "Fewest Transfers",
327
- value: "TRANSFERS"
328
- });
329
- }
330
-
331
323
  return opts;
332
324
  },
333
325
  itineraryRewrite: value => ({ optimize: value })