@opentripplanner/core-utils 6.0.1-alpha.1 → 7.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/esm/itinerary.js +74 -11
  2. package/esm/itinerary.js.map +1 -1
  3. package/esm/map.js +19 -16
  4. package/esm/map.js.map +1 -1
  5. package/esm/query.js +14 -11
  6. package/esm/query.js.map +1 -1
  7. package/esm/time.js +5 -56
  8. package/esm/time.js.map +1 -1
  9. package/lib/itinerary.d.ts +14 -7
  10. package/lib/itinerary.d.ts.map +1 -1
  11. package/lib/itinerary.js +79 -65
  12. package/lib/itinerary.js.map +1 -1
  13. package/lib/map.d.ts +3 -3
  14. package/lib/map.d.ts.map +1 -1
  15. package/lib/map.js +18 -32
  16. package/lib/map.js.map +1 -1
  17. package/lib/query.js +11 -15
  18. package/lib/query.js.map +1 -1
  19. package/lib/time.d.ts +1 -16
  20. package/lib/time.d.ts.map +1 -1
  21. package/lib/time.js +4 -72
  22. package/lib/time.js.map +1 -1
  23. package/package.json +6 -7
  24. package/src/__tests__/__snapshots__/itinerary.js.snap +2 -38
  25. package/src/__tests__/__snapshots__/time.js.snap +7 -13
  26. package/src/__tests__/itinerary.js +6 -29
  27. package/src/__tests__/time.js +7 -27
  28. package/src/itinerary.ts +72 -27
  29. package/src/map.ts +17 -22
  30. package/src/query.js +19 -16
  31. package/src/time.ts +11 -76
  32. package/tsconfig.tsbuildinfo +1294 -1311
  33. package/esm/deprecated-with-types.js +0 -47
  34. package/esm/deprecated-with-types.js.map +0 -1
  35. package/esm/deprecated.js +0 -325
  36. package/esm/deprecated.js.map +0 -1
  37. package/lib/deprecated-with-types.d.ts +0 -23
  38. package/lib/deprecated-with-types.d.ts.map +0 -1
  39. package/lib/deprecated-with-types.js +0 -61
  40. package/lib/deprecated-with-types.js.map +0 -1
  41. package/lib/deprecated.js +0 -355
  42. package/lib/deprecated.js.map +0 -1
  43. package/src/__tests__/__mocks__/multi-currency-itinerary.json +0 -1728
  44. package/src/deprecated-with-types.ts +0 -62
  45. package/src/deprecated.js +0 -334
package/lib/deprecated.js DELETED
@@ -1,355 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.logDeprecationWarning = logDeprecationWarning;
9
- exports.getStepDirection = getStepDirection;
10
- exports.getStepInstructions = getStepInstructions;
11
- exports.getStepStreetName = getStepStreetName;
12
- exports.getLegModeLabel = getLegModeLabel;
13
- exports.getModeForPlace = getModeForPlace;
14
- exports.getPlaceName = getPlaceName;
15
- exports.getTransitFare = getTransitFare;
16
- exports.calculateFares = calculateFares;
17
- exports.latlngToString = latlngToString;
18
- exports.coordsToString = coordsToString;
19
- exports.getDetailText = getDetailText;
20
- exports.summarizeQuery = summarizeQuery;
21
- exports.getTimeZoneOffset = getTimeZoneOffset;
22
-
23
- var _moment = _interopRequireDefault(require("moment"));
24
-
25
- /**
26
- * To disable cyclic dependency resolution we need to require() within methods
27
- * This is a good reason to disable this eslint-rule
28
- */
29
-
30
- /* eslint-disable global-require */
31
-
32
- /**
33
- * Generates a warning to tell developer that they are using deprecated methods!
34
- */
35
- function logDeprecationWarning(method, alternative) {
36
- console.warn(`${method || "This method"} is deprecated and will be removed in a future otp-ui release. All language functionality should be handled using react-intl.
37
- ${alternative ? `
38
-
39
- Use ${alternative} instead, which provides a new interface that doesn't return English strings.` : ""}`);
40
- } // itinerary.js
41
-
42
-
43
- function getStepDirection(step) {
44
- logDeprecationWarning("getStepDirection");
45
-
46
- switch (step.relativeDirection) {
47
- case "DEPART":
48
- return `Head ${step.absoluteDirection.toLowerCase()}`;
49
-
50
- case "LEFT":
51
- return "Left";
52
-
53
- case "HARD_LEFT":
54
- return "Hard left";
55
-
56
- case "SLIGHTLY_LEFT":
57
- return "Slight left";
58
-
59
- case "CONTINUE":
60
- return "Continue";
61
-
62
- case "SLIGHTLY_RIGHT":
63
- return "Slight right";
64
-
65
- case "RIGHT":
66
- return "Right";
67
-
68
- case "HARD_RIGHT":
69
- return "Hard right";
70
-
71
- case "CIRCLE_CLOCKWISE":
72
- return "Follow circle clockwise";
73
-
74
- case "CIRCLE_COUNTERCLOCKWISE":
75
- return "Follow circle counterclockwise";
76
-
77
- case "ELEVATOR":
78
- return "Take elevator";
79
-
80
- case "UTURN_LEFT":
81
- return "Left U-turn";
82
-
83
- case "UTURN_RIGHT":
84
- return "Right U-turn";
85
-
86
- default:
87
- return step.relativeDirection;
88
- }
89
- }
90
-
91
- function getStepInstructions(step) {
92
- logDeprecationWarning("getStepInstructions");
93
- const conjunction = step.relativeDirection === "ELEVATOR" ? "to" : "on";
94
- return `${getStepDirection(step)} ${conjunction} ${step.streetName}`;
95
- }
96
-
97
- function getStepStreetName(step) {
98
- logDeprecationWarning("getStepStreetName");
99
- if (step.streetName === "road") return "Unnamed Road";
100
- if (step.streetName === "path") return "Unnamed Path";
101
- return step.streetName;
102
- }
103
-
104
- function getLegModeLabel(leg) {
105
- logDeprecationWarning("getLegModeLabel");
106
-
107
- switch (leg.mode) {
108
- case "BICYCLE_RENT":
109
- return "Biketown";
110
-
111
- case "CAR":
112
- return leg.hailedCar ? "Ride" : "Drive";
113
-
114
- case "GONDOLA":
115
- return "Aerial Tram";
116
-
117
- case "TRAM":
118
- if (leg.routeLongName.toLowerCase().indexOf("streetcar") !== -1) return "Streetcar";
119
- return "Light Rail";
120
-
121
- case "MICROMOBILITY":
122
- case "SCOOTER":
123
- return "Ride";
124
-
125
- default:
126
- return require("./itinerary").toSentenceCase(leg.mode);
127
- }
128
- }
129
- /**
130
- * Returns mode name by checking the vertex type (VertexType class in OTP) for
131
- * the provided place. NOTE: this is currently only intended for vehicles at
132
- * the moment (not transit or walking).
133
- *
134
- * @param {string} place place from itinerary leg
135
- */
136
-
137
-
138
- function getModeForPlace(place) {
139
- logDeprecationWarning("getModeForPlace");
140
-
141
- switch (place.vertexType) {
142
- case "CARSHARE":
143
- return "car";
144
-
145
- case "VEHICLERENTAL":
146
- return "E-scooter";
147
- // TODO: Should the type change depending on bike vertex type?
148
-
149
- case "BIKESHARE":
150
- case "BIKEPARK":
151
- return "bike";
152
- // If company offers more than one mode, default to `vehicle` string.
153
-
154
- default:
155
- return "vehicle";
156
- }
157
- }
158
-
159
- function getPlaceName(place, companies) {
160
- logDeprecationWarning("getPlaceName"); // If address is provided (i.e. for carshare station, use it)
161
-
162
- if (place.address) return place.address.split(",")[0];
163
-
164
- if (place.networks && place.vertexType === "VEHICLERENTAL") {
165
- // For vehicle rental pick up, do not use the place name. Rather, use
166
- // company name + vehicle type (e.g., SPIN E-scooter). Place name is often just
167
- // a UUID that has no relevance to the actual vehicle. For bikeshare, however,
168
- // there are often hubs or bikes that have relevant names to the user.
169
- const company = require("./itinerary").getCompanyForNetwork(place.networks[0], companies);
170
-
171
- if (company) {
172
- return `${company.label} ${getModeForPlace(place)}`;
173
- }
174
- } // Default to place name
175
-
176
-
177
- return place.name;
178
- }
179
- /**
180
- * For a given fare component (either total fare or component parts), returns
181
- * an object with string formatters and the fare value (in cents).
182
- */
183
-
184
-
185
- function getTransitFare(fareComponent) {
186
- logDeprecationWarning("getTransitFare", "the fare object and getTncFare"); // Default values (if fare component is not valid).
187
-
188
- let digits = 2;
189
- let transitFare = 0;
190
- let symbol = "$";
191
- let currencyCode = "USD";
192
-
193
- if (fareComponent) {
194
- // Assign values without declaration. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration
195
- ({
196
- currencyCode,
197
- defaultFractionDigits: digits,
198
- symbol
199
- } = fareComponent.currency);
200
- transitFare = fareComponent.cents;
201
- } // For cents to string conversion, use digits from fare component.
202
-
203
-
204
- const centsToString = cents => {
205
- const dollars = (cents / 10 ** digits).toFixed(digits);
206
- return `${symbol}${dollars}`;
207
- }; // For dollars to string conversion, assume we're rounding to two digits.
208
-
209
-
210
- const dollarsToString = dollars => `${symbol}${dollars.toFixed(2)}`;
211
-
212
- return {
213
- centsToString,
214
- currencyCode,
215
- dollarsToString,
216
- transitFare
217
- };
218
- }
219
- /**
220
- * For an itinerary, calculates the transit/TNC fares and returns an object with
221
- * these values, currency info, as well as string formatters.
222
- * It is assumed that the same currency is used for transit and TNC legs.
223
- *
224
- * multiple being set to true will change the output behavior:
225
- * - dollarsToString and centsToString will be returned as part of each fare
226
- * - currencyCode will be returned separately for each fare
227
- * - tnc currency code will be returned separately
228
- * - each fare type will be returned separately within a new transitFares property
229
- *
230
- * FIXME: a new approach to fare calculation must be found:
231
- * the current approach is not sustainable, as centsToString and DollarsToString
232
- * must be replaced by i18n anyway.
233
- *
234
- * However, the current behavior should ideally be kept to avoid a breaking change.
235
- * The "multiple" mode is helpful, but only prevents tnc fare calculation from being duplicated.
236
- * This method could be split out into a new one, along with tnc fare calculation.
237
- * If this is done, the individual fare calculation should also be modified to support
238
- * a default fare not being called "regular". However, this again would be a breaking change.
239
- * This breaking change is avoided by adding the "multiple" parameter.
240
- *
241
- * When centsToString and dollarsToString are removed, this method should be split into
242
- * individual fare calculation on a variable fare key, fare calculation of an entire leg,
243
- * which will get fares for every fare key in the leg, and a method to calculate the fare of
244
- * a tnc ride within the leg. This will make typescripting easier, as the types will be cleaner.
245
- */
246
-
247
-
248
- function calculateFares(itinerary, multiple = false) {
249
- logDeprecationWarning("calculateFares", "the fare object and getTncFare"); // Process any TNC fares
250
-
251
- let minTNCFare = 0;
252
- let maxTNCFare = 0;
253
- let tncCurrencyCode;
254
- itinerary.legs.forEach(leg => {
255
- if (leg.mode === "CAR" && leg.hailedCar && leg.tncData) {
256
- const {
257
- currency,
258
- maxCost,
259
- minCost
260
- } = leg.tncData; // TODO: Support non-USD
261
-
262
- minTNCFare += minCost;
263
- maxTNCFare += maxCost;
264
- tncCurrencyCode = currency;
265
- }
266
- });
267
-
268
- if (multiple) {
269
- // Return object of fares
270
- const transitFares = {};
271
-
272
- if (itinerary && itinerary.fare && itinerary.fare.fare) {
273
- Object.keys(itinerary.fare.fare).forEach(fareKey => {
274
- const fareComponent = itinerary.fare.fare[fareKey];
275
- transitFares[fareKey] = getTransitFare(fareComponent);
276
- });
277
- }
278
-
279
- return {
280
- maxTNCFare,
281
- minTNCFare,
282
- tncCurrencyCode,
283
- transitFares
284
- };
285
- } // Extract fare total from itinerary fares.
286
-
287
-
288
- const fareComponent = itinerary.fare && itinerary.fare.fare && itinerary.fare.fare.regular; // Get string formatters and itinerary fare.
289
-
290
- const {
291
- centsToString,
292
- currencyCode: transitCurrencyCode,
293
- dollarsToString,
294
- transitFare
295
- } = getTransitFare(fareComponent);
296
- return {
297
- centsToString,
298
- currencyCode: transitCurrencyCode || tncCurrencyCode,
299
- dollarsToString,
300
- maxTNCFare,
301
- minTNCFare,
302
- transitFare
303
- };
304
- } // map.js
305
-
306
-
307
- function latlngToString(latlng) {
308
- logDeprecationWarning("latlngToString", "the latlng object");
309
- return latlng && `${latlng.lat.toFixed(5)}, ${(latlng.lng || latlng.lon).toFixed(5)}`;
310
- }
311
-
312
- function coordsToString(coords) {
313
- logDeprecationWarning("coordsToString", "the coords object");
314
- return coords.length && coords.map(c => (+c).toFixed(5)).join(", ");
315
- }
316
-
317
- function getDetailText(location) {
318
- let detailText;
319
-
320
- if (location.type === "home" || location.type === "work") {
321
- detailText = location.name;
322
- }
323
-
324
- if (location.type === "stop") {
325
- detailText = location.id;
326
- } else if (location.type === "recent" && location.timestamp) {
327
- detailText = (0, _moment.default)(location.timestamp).fromNow();
328
- }
329
-
330
- return detailText;
331
- } // query.js
332
-
333
-
334
- function summarizeQuery(query, locations = []) {
335
- logDeprecationWarning("summarizeQuery");
336
-
337
- function findLocationType(location, ls = [], types = ["home", "work", "suggested"]) {
338
- const match = ls.find(l => require("./map").matchLatLon(l, location));
339
- return match && types.indexOf(match.type) !== -1 ? match.type : null;
340
- }
341
-
342
- const from = findLocationType(query.from, locations) || query.from.name.split(",")[0];
343
- const to = findLocationType(query.to, locations) || query.to.name.split(",")[0];
344
- const mode = require("./itinerary").hasTransit(query.mode) ? "Transit" : require("./itinerary").toSentenceCase(query.mode);
345
- return `${mode} from ${from} to ${to}`;
346
- }
347
-
348
- function getTimeZoneOffset(itinerary) {
349
- logDeprecationWarning("getTimeZoneOffset");
350
- if (!itinerary.legs || !itinerary.legs.length) return 0; // Determine if there is a DST offset between now and the itinerary start date
351
-
352
- const dstOffset = new Date(itinerary.startTime).getTimezoneOffset() - new Date().getTimezoneOffset();
353
- return itinerary.legs[0].agencyTimeZoneOffset + (new Date().getTimezoneOffset() + dstOffset) * 60000;
354
- }
355
- //# sourceMappingURL=deprecated.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/deprecated.js"],"names":["logDeprecationWarning","method","alternative","console","warn","getStepDirection","step","relativeDirection","absoluteDirection","toLowerCase","getStepInstructions","conjunction","streetName","getStepStreetName","getLegModeLabel","leg","mode","hailedCar","routeLongName","indexOf","require","toSentenceCase","getModeForPlace","place","vertexType","getPlaceName","companies","address","split","networks","company","getCompanyForNetwork","label","name","getTransitFare","fareComponent","digits","transitFare","symbol","currencyCode","defaultFractionDigits","currency","cents","centsToString","dollars","toFixed","dollarsToString","calculateFares","itinerary","multiple","minTNCFare","maxTNCFare","tncCurrencyCode","legs","forEach","tncData","maxCost","minCost","transitFares","fare","Object","keys","fareKey","regular","transitCurrencyCode","latlngToString","latlng","lat","lng","lon","coordsToString","coords","length","map","c","join","getDetailText","location","detailText","type","id","timestamp","fromNow","summarizeQuery","query","locations","findLocationType","ls","types","match","find","l","matchLatLon","from","to","hasTransit","getTimeZoneOffset","dstOffset","Date","startTime","getTimezoneOffset","agencyTimeZoneOffset"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;;AACA;;AAEA;AACA;AACA;AACO,SAASA,qBAAT,CAA+BC,MAA/B,EAAuCC,WAAvC,EAAoD;AACzDC,EAAAA,OAAO,CAACC,IAAR,CACG,GAAE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WT,SAAX,CAAhB,IAAyCD,KAAK,CAACU,EAAN,CAAS7D,IAAT,CAAcL,KAAd,CAAoB,GAApB,EAAyB,CAAzB,CAD3C;AAEA,QAAMZ,IAAI,GAAGI,OAAO,CAAC,aAAD,CAAP,CAAuB2E,UAAvB,CAAkCX,KAAK,CAACpE,IAAxC,IACT,SADS,GAETI,OAAO,CAAC,aAAD,CAAP,CAAuBC,cAAvB,CAAsC+D,KAAK,CAACpE,IAA5C,CAFJ;AAGA,SAAQ,GAAEA,IAAK,SAAQ6E,IAAK,OAAMC,EAAG,EAArC;AACD;;AAEM,SAASE,iBAAT,CAA2BhD,SAA3B,EAAsC;AAC3ChD,EAAAA,qBAAqB,CAAC,mBAAD,CAArB;AAEA,MAAI,CAACgD,SAAS,CAACK,IAAX,IAAmB,CAACL,SAAS,CAACK,IAAV,CAAemB,MAAvC,EAA+C,OAAO,CAAP,CAHJ,CAK3C;;AACA,QAAMyB,SAAS,GACb,IAAIC,IAAJ,CAASlD,SAAS,CAACmD,SAAnB,EAA8BC,iBAA9B,KACA,IAAIF,IAAJ,GAAWE,iBAAX,EAFF;AAIA,SACEpD,SAAS,CAACK,IAAV,CAAe,CAAf,EAAkBgD,oBAAlB,GACA,CAAC,IAAIH,IAAJ,GAAWE,iBAAX,KAAiCH,SAAlC,IAA+C,KAFjD;AAID","sourcesContent":["import moment from \"moment\";\n\n/**\n * To disable cyclic dependency resolution we need to require() within methods\n * This is a good reason to disable this eslint-rule\n */\n/* eslint-disable global-require */\n\n/**\n * Generates a warning to tell developer that they are using deprecated methods!\n */\nexport function logDeprecationWarning(method, alternative) {\n console.warn(\n `${method ||\n \"This method\"} is deprecated and will be removed in a future otp-ui release. All language functionality should be handled using react-intl.\n ${\n alternative\n ? `\n\n Use ${alternative} instead, which provides a new interface that doesn't return English strings.`\n : \"\"\n }`\n );\n}\n\n// itinerary.js\n\nexport function getStepDirection(step) {\n logDeprecationWarning(\"getStepDirection\");\n\n switch (step.relativeDirection) {\n case \"DEPART\":\n return `Head ${step.absoluteDirection.toLowerCase()}`;\n case \"LEFT\":\n return \"Left\";\n case \"HARD_LEFT\":\n return \"Hard left\";\n case \"SLIGHTLY_LEFT\":\n return \"Slight left\";\n case \"CONTINUE\":\n return \"Continue\";\n case \"SLIGHTLY_RIGHT\":\n return \"Slight right\";\n case \"RIGHT\":\n return \"Right\";\n case \"HARD_RIGHT\":\n return \"Hard right\";\n case \"CIRCLE_CLOCKWISE\":\n return \"Follow circle clockwise\";\n case \"CIRCLE_COUNTERCLOCKWISE\":\n return \"Follow circle counterclockwise\";\n case \"ELEVATOR\":\n return \"Take elevator\";\n case \"UTURN_LEFT\":\n return \"Left U-turn\";\n case \"UTURN_RIGHT\":\n return \"Right U-turn\";\n default:\n return step.relativeDirection;\n }\n}\n\nexport function getStepInstructions(step) {\n logDeprecationWarning(\"getStepInstructions\");\n\n const conjunction = step.relativeDirection === \"ELEVATOR\" ? \"to\" : \"on\";\n return `${getStepDirection(step)} ${conjunction} ${step.streetName}`;\n}\n\nexport function getStepStreetName(step) {\n logDeprecationWarning(\"getStepStreetName\");\n\n if (step.streetName === \"road\") return \"Unnamed Road\";\n if (step.streetName === \"path\") return \"Unnamed Path\";\n return step.streetName;\n}\n\nexport function getLegModeLabel(leg) {\n logDeprecationWarning(\"getLegModeLabel\");\n\n switch (leg.mode) {\n case \"BICYCLE_RENT\":\n return \"Biketown\";\n case \"CAR\":\n return leg.hailedCar ? \"Ride\" : \"Drive\";\n case \"GONDOLA\":\n return \"Aerial Tram\";\n case \"TRAM\":\n if (leg.routeLongName.toLowerCase().indexOf(\"streetcar\") !== -1)\n return \"Streetcar\";\n return \"Light Rail\";\n case \"MICROMOBILITY\":\n case \"SCOOTER\":\n return \"Ride\";\n default:\n return require(\"./itinerary\").toSentenceCase(leg.mode);\n }\n}\n\n/**\n * Returns mode name by checking the vertex type (VertexType class in OTP) for\n * the provided place. NOTE: this is currently only intended for vehicles at\n * the moment (not transit or walking).\n *\n * @param {string} place place from itinerary leg\n */\nexport function getModeForPlace(place) {\n logDeprecationWarning(\"getModeForPlace\");\n\n switch (place.vertexType) {\n case \"CARSHARE\":\n return \"car\";\n case \"VEHICLERENTAL\":\n return \"E-scooter\";\n // TODO: Should the type change depending on bike vertex type?\n case \"BIKESHARE\":\n case \"BIKEPARK\":\n return \"bike\";\n // If company offers more than one mode, default to `vehicle` string.\n default:\n return \"vehicle\";\n }\n}\n\nexport function getPlaceName(place, companies) {\n logDeprecationWarning(\"getPlaceName\");\n\n // If address is provided (i.e. for carshare station, use it)\n if (place.address) return place.address.split(\",\")[0];\n if (place.networks && place.vertexType === \"VEHICLERENTAL\") {\n // For vehicle rental pick up, do not use the place name. Rather, use\n // company name + vehicle type (e.g., SPIN E-scooter). Place name is often just\n // a UUID that has no relevance to the actual vehicle. For bikeshare, however,\n // there are often hubs or bikes that have relevant names to the user.\n const company = require(\"./itinerary\").getCompanyForNetwork(\n place.networks[0],\n companies\n );\n if (company) {\n return `${company.label} ${getModeForPlace(place)}`;\n }\n }\n // Default to place name\n return place.name;\n}\n\n/**\n * For a given fare component (either total fare or component parts), returns\n * an object with string formatters and the fare value (in cents).\n */\nexport function getTransitFare(fareComponent) {\n logDeprecationWarning(\"getTransitFare\", \"the fare object and getTncFare\");\n\n // Default values (if fare component is not valid).\n let digits = 2;\n let transitFare = 0;\n let symbol = \"$\";\n let currencyCode = \"USD\";\n if (fareComponent) {\n // Assign values without declaration. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration\n ({\n currencyCode,\n defaultFractionDigits: digits,\n symbol\n } = fareComponent.currency);\n transitFare = fareComponent.cents;\n }\n // For cents to string conversion, use digits from fare component.\n const centsToString = cents => {\n const dollars = (cents / 10 ** digits).toFixed(digits);\n return `${symbol}${dollars}`;\n };\n // For dollars to string conversion, assume we're rounding to two digits.\n const dollarsToString = dollars => `${symbol}${dollars.toFixed(2)}`;\n return {\n centsToString,\n currencyCode,\n dollarsToString,\n transitFare\n };\n}\n\n/**\n * For an itinerary, calculates the transit/TNC fares and returns an object with\n * these values, currency info, as well as string formatters.\n * It is assumed that the same currency is used for transit and TNC legs.\n *\n * multiple being set to true will change the output behavior:\n * - dollarsToString and centsToString will be returned as part of each fare\n * - currencyCode will be returned separately for each fare\n * - tnc currency code will be returned separately\n * - each fare type will be returned separately within a new transitFares property\n *\n * FIXME: a new approach to fare calculation must be found:\n * the current approach is not sustainable, as centsToString and DollarsToString\n * must be replaced by i18n anyway.\n *\n * However, the current behavior should ideally be kept to avoid a breaking change.\n * The \"multiple\" mode is helpful, but only prevents tnc fare calculation from being duplicated.\n * This method could be split out into a new one, along with tnc fare calculation.\n * If this is done, the individual fare calculation should also be modified to support\n * a default fare not being called \"regular\". However, this again would be a breaking change.\n * This breaking change is avoided by adding the \"multiple\" parameter.\n *\n * When centsToString and dollarsToString are removed, this method should be split into\n * individual fare calculation on a variable fare key, fare calculation of an entire leg,\n * which will get fares for every fare key in the leg, and a method to calculate the fare of\n * a tnc ride within the leg. This will make typescripting easier, as the types will be cleaner.\n */\nexport function calculateFares(itinerary, multiple = false) {\n logDeprecationWarning(\"calculateFares\", \"the fare object and getTncFare\");\n\n // Process any TNC fares\n let minTNCFare = 0;\n let maxTNCFare = 0;\n let tncCurrencyCode;\n itinerary.legs.forEach(leg => {\n if (leg.mode === \"CAR\" && leg.hailedCar && leg.tncData) {\n const { currency, maxCost, minCost } = leg.tncData;\n // TODO: Support non-USD\n minTNCFare += minCost;\n maxTNCFare += maxCost;\n tncCurrencyCode = currency;\n }\n });\n\n if (multiple) {\n // Return object of fares\n const transitFares = {};\n if (itinerary && itinerary.fare && itinerary.fare.fare) {\n Object.keys(itinerary.fare.fare).forEach(fareKey => {\n const fareComponent = itinerary.fare.fare[fareKey];\n transitFares[fareKey] = getTransitFare(fareComponent);\n });\n }\n\n return {\n maxTNCFare,\n minTNCFare,\n tncCurrencyCode,\n transitFares\n };\n }\n\n // Extract fare total from itinerary fares.\n const fareComponent =\n itinerary.fare && itinerary.fare.fare && itinerary.fare.fare.regular;\n // Get string formatters and itinerary fare.\n const {\n centsToString,\n currencyCode: transitCurrencyCode,\n dollarsToString,\n transitFare\n } = getTransitFare(fareComponent);\n\n return {\n centsToString,\n currencyCode: transitCurrencyCode || tncCurrencyCode,\n dollarsToString,\n maxTNCFare,\n minTNCFare,\n transitFare\n };\n}\n\n// map.js\n\nexport function latlngToString(latlng) {\n logDeprecationWarning(\"latlngToString\", \"the latlng object\");\n\n return (\n latlng &&\n `${latlng.lat.toFixed(5)}, ${(latlng.lng || latlng.lon).toFixed(5)}`\n );\n}\n\nexport function coordsToString(coords) {\n logDeprecationWarning(\"coordsToString\", \"the coords object\");\n\n return coords.length && coords.map(c => (+c).toFixed(5)).join(\", \");\n}\n\nexport function getDetailText(location) {\n let detailText;\n if (location.type === \"home\" || location.type === \"work\") {\n detailText = location.name;\n }\n if (location.type === \"stop\") {\n detailText = location.id;\n } else if (location.type === \"recent\" && location.timestamp) {\n detailText = moment(location.timestamp).fromNow();\n }\n return detailText;\n}\n\n// query.js\n\nexport function summarizeQuery(query, locations = []) {\n logDeprecationWarning(\"summarizeQuery\");\n\n function findLocationType(\n location,\n ls = [],\n types = [\"home\", \"work\", \"suggested\"]\n ) {\n const match = ls.find(l => require(\"./map\").matchLatLon(l, location));\n return match && types.indexOf(match.type) !== -1 ? match.type : null;\n }\n\n const from =\n findLocationType(query.from, locations) || query.from.name.split(\",\")[0];\n const to =\n findLocationType(query.to, locations) || query.to.name.split(\",\")[0];\n const mode = require(\"./itinerary\").hasTransit(query.mode)\n ? \"Transit\"\n : require(\"./itinerary\").toSentenceCase(query.mode);\n return `${mode} from ${from} to ${to}`;\n}\n\nexport function getTimeZoneOffset(itinerary) {\n logDeprecationWarning(\"getTimeZoneOffset\");\n\n if (!itinerary.legs || !itinerary.legs.length) return 0;\n\n // Determine if there is a DST offset between now and the itinerary start date\n const dstOffset =\n new Date(itinerary.startTime).getTimezoneOffset() -\n new Date().getTimezoneOffset();\n\n return (\n itinerary.legs[0].agencyTimeZoneOffset +\n (new Date().getTimezoneOffset() + dstOffset) * 60000\n );\n}\n"],"file":"deprecated.js"}