@opentripplanner/core-utils 4.8.1-alpha → 4.10.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.
- package/esm/deprecated.js +309 -0
- package/esm/deprecated.js.map +1 -0
- package/esm/itinerary.js +16 -247
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +9 -25
- package/esm/map.js.map +1 -1
- package/esm/messages.js +4 -0
- package/esm/messages.js.map +1 -1
- package/esm/profile.js +7 -12
- package/esm/profile.js.map +1 -1
- package/esm/query-params.js +10 -7
- package/esm/query-params.js.map +1 -1
- package/esm/query.js +4 -19
- package/esm/query.js.map +1 -1
- package/esm/time.js +36 -6
- package/esm/time.js.map +1 -1
- package/lib/deprecated.js +338 -0
- package/lib/deprecated.js.map +1 -0
- package/lib/itinerary.js +64 -258
- package/lib/itinerary.js.map +1 -1
- package/lib/map.js +26 -32
- package/lib/map.js.map +1 -1
- package/lib/messages.js +5 -0
- package/lib/messages.js.map +1 -1
- package/lib/profile.js +7 -12
- package/lib/profile.js.map +1 -1
- package/lib/query-params.js +11 -6
- package/lib/query-params.js.map +1 -1
- package/lib/query.js +9 -14
- package/lib/query.js.map +1 -1
- package/lib/time.js +39 -5
- package/lib/time.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/query-params.js.snap +1 -1
- package/src/__tests__/__snapshots__/query.js.snap +6 -6
- package/src/deprecated.js +310 -0
- package/src/itinerary.js +33 -221
- package/src/map.js +13 -25
- package/src/messages.js +4 -0
- package/src/profile.js +6 -16
- package/src/query-params.js +13 -5
- package/src/query.js +6 -26
- package/src/time.js +35 -5
package/src/profile.js
CHANGED
|
@@ -27,8 +27,8 @@ export function filterProfileOptions(response) {
|
|
|
27
27
|
return response;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function locationString(str
|
|
31
|
-
return str ? str.split(",")[0] :
|
|
30
|
+
function locationString(str) {
|
|
31
|
+
return str ? str.split(",")[0] : null;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function accessToLeg(access, origin, destination) {
|
|
@@ -37,10 +37,10 @@ function accessToLeg(access, origin, destination) {
|
|
|
37
37
|
duration: access.time,
|
|
38
38
|
transitLeg: false,
|
|
39
39
|
from: {
|
|
40
|
-
name: locationString(origin
|
|
40
|
+
name: locationString(origin)
|
|
41
41
|
},
|
|
42
42
|
to: {
|
|
43
|
-
name: locationString(destination
|
|
43
|
+
name: locationString(destination)
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
}
|
|
@@ -98,7 +98,7 @@ function optionToItinerary(option, query) {
|
|
|
98
98
|
duration: walkOnTime,
|
|
99
99
|
transitLeg: false,
|
|
100
100
|
from: {
|
|
101
|
-
name: locationString(query && query.from.name
|
|
101
|
+
name: locationString(query && query.from.name)
|
|
102
102
|
},
|
|
103
103
|
to: {
|
|
104
104
|
name: onStationName
|
|
@@ -127,7 +127,7 @@ function optionToItinerary(option, query) {
|
|
|
127
127
|
name: offStationName
|
|
128
128
|
},
|
|
129
129
|
to: {
|
|
130
|
-
name: locationString(query && query.to.name
|
|
130
|
+
name: locationString(query && query.to.name)
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
133
|
} else {
|
|
@@ -177,16 +177,6 @@ function optionToItinerary(option, query) {
|
|
|
177
177
|
itin.walkTime += option.egress[0].time;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
// construct summary
|
|
181
|
-
if (option.transit) {
|
|
182
|
-
itin.summary = "Transit";
|
|
183
|
-
} else if (option.modes.length === 1 && option.modes[0] === "bicycle")
|
|
184
|
-
itin.summary = "Bicycle";
|
|
185
|
-
else if (option.modes.length === 1 && option.modes[0] === "walk")
|
|
186
|
-
itin.summary = "Walk";
|
|
187
|
-
else if (option.modes.indexOf("bicycle_rent") !== -1)
|
|
188
|
-
itin.summary = "Bikeshare";
|
|
189
|
-
|
|
190
180
|
return itin;
|
|
191
181
|
}
|
|
192
182
|
|
package/src/query-params.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// TODO: Remove this entire file, as it is deprecated in favor of i18n-queryParams within
|
|
2
|
+
// the SettingsSelector package
|
|
3
|
+
|
|
4
|
+
// This is only used within stories
|
|
1
5
|
import cloneDeep from "lodash.clonedeep";
|
|
2
6
|
import React from "react";
|
|
3
7
|
import { Wheelchair } from "@styled-icons/foundation/Wheelchair";
|
|
@@ -54,10 +58,14 @@ import { getCurrentDate, getCurrentTime } from "./time";
|
|
|
54
58
|
/**
|
|
55
59
|
* Format location object as string for use in fromPlace or toPlace query param.
|
|
56
60
|
*/
|
|
57
|
-
export function formatPlace(location, alternateName
|
|
61
|
+
export function formatPlace(location, alternateName) {
|
|
58
62
|
if (!location) return null;
|
|
59
63
|
const name =
|
|
60
|
-
location.name ||
|
|
64
|
+
location.name ||
|
|
65
|
+
`${alternateName ? `${alternateName} ` : ""}(${location.lat},${
|
|
66
|
+
location.lon
|
|
67
|
+
})`;
|
|
68
|
+
// This string is not language-specific
|
|
61
69
|
return `${name}::${location.lat},${location.lon}`;
|
|
62
70
|
}
|
|
63
71
|
|
|
@@ -70,7 +78,7 @@ const queryParams = [
|
|
|
70
78
|
name: "from",
|
|
71
79
|
routingTypes: ["ITINERARY", "PROFILE"],
|
|
72
80
|
default: null,
|
|
73
|
-
itineraryRewrite: value => ({ fromPlace: formatPlace(value
|
|
81
|
+
itineraryRewrite: value => ({ fromPlace: formatPlace(value) }),
|
|
74
82
|
profileRewrite: value => ({ from: { lat: value.lat, lon: value.lon } })
|
|
75
83
|
// FIXME: Use for parsing URL values?
|
|
76
84
|
// fromURL: stringToLocation
|
|
@@ -81,7 +89,7 @@ const queryParams = [
|
|
|
81
89
|
name: "to",
|
|
82
90
|
routingTypes: ["ITINERARY", "PROFILE"],
|
|
83
91
|
default: null,
|
|
84
|
-
itineraryRewrite: value => ({ toPlace: formatPlace(value
|
|
92
|
+
itineraryRewrite: value => ({ toPlace: formatPlace(value) }),
|
|
85
93
|
profileRewrite: value => ({ to: { lat: value.lat, lon: value.lon } })
|
|
86
94
|
// FIXME: Use for parsing URL values?
|
|
87
95
|
// fromURL: stringToLocation
|
|
@@ -161,7 +169,7 @@ const queryParams = [
|
|
|
161
169
|
routingTypes: ["ITINERARY"],
|
|
162
170
|
applicable: query =>
|
|
163
171
|
query.mode && hasTransit(query.mode) && query.mode.indexOf("WALK") !== -1,
|
|
164
|
-
default:
|
|
172
|
+
default: 1207, // 3/4 mi.
|
|
165
173
|
selector: "DROPDOWN",
|
|
166
174
|
label: "Maximum Walk",
|
|
167
175
|
options: [
|
package/src/query.js
CHANGED
|
@@ -2,14 +2,8 @@ import moment from "moment";
|
|
|
2
2
|
import getGeocoder from "@opentripplanner/geocoder/lib";
|
|
3
3
|
import qs from "qs";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
hasCar,
|
|
8
|
-
hasTransit,
|
|
9
|
-
isAccessMode,
|
|
10
|
-
toSentenceCase
|
|
11
|
-
} from "./itinerary";
|
|
12
|
-
import { coordsToString, matchLatLon, stringToCoords } from "./map";
|
|
5
|
+
import { getTransitModes, hasCar, isAccessMode } from "./itinerary";
|
|
6
|
+
import { stringToCoords } from "./map";
|
|
13
7
|
import queryParams from "./query-params";
|
|
14
8
|
import {
|
|
15
9
|
getCurrentTime,
|
|
@@ -18,6 +12,10 @@ import {
|
|
|
18
12
|
OTP_API_TIME_FORMAT
|
|
19
13
|
} from "./time";
|
|
20
14
|
|
|
15
|
+
import { coordsToString, summarizeQuery } from "./deprecated";
|
|
16
|
+
|
|
17
|
+
export { summarizeQuery };
|
|
18
|
+
|
|
21
19
|
/* The list of default parameters considered in the settings panel */
|
|
22
20
|
|
|
23
21
|
export const defaultParams = [
|
|
@@ -84,24 +82,6 @@ export function getOtpUrlParams() {
|
|
|
84
82
|
return Object.keys(getUrlParams()).filter(key => !key.startsWith("ui_"));
|
|
85
83
|
}
|
|
86
84
|
|
|
87
|
-
function findLocationType(
|
|
88
|
-
location,
|
|
89
|
-
locations = [],
|
|
90
|
-
types = ["home", "work", "suggested"]
|
|
91
|
-
) {
|
|
92
|
-
const match = locations.find(l => matchLatLon(l, location));
|
|
93
|
-
return match && types.indexOf(match.type) !== -1 ? match.type : null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function summarizeQuery(query, locations = []) {
|
|
97
|
-
const from =
|
|
98
|
-
findLocationType(query.from, locations) || query.from.name.split(",")[0];
|
|
99
|
-
const to =
|
|
100
|
-
findLocationType(query.to, locations) || query.to.name.split(",")[0];
|
|
101
|
-
const mode = hasTransit(query.mode) ? "Transit" : toSentenceCase(query.mode);
|
|
102
|
-
return `${mode} from ${from} to ${to}`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
85
|
export function getTripOptionsFromQuery(query, keepPlace = false) {
|
|
106
86
|
const options = { ...query };
|
|
107
87
|
// Delete time/date options and from/to
|
package/src/time.js
CHANGED
|
@@ -23,7 +23,11 @@ export const OTP_API_TIME_FORMAT = "HH:mm";
|
|
|
23
23
|
* Otherwise, uses date-fns default
|
|
24
24
|
* @returns Formatted duration
|
|
25
25
|
*/
|
|
26
|
-
function formatDurationLikeMoment(
|
|
26
|
+
function formatDurationLikeMoment(
|
|
27
|
+
seconds,
|
|
28
|
+
showSeconds,
|
|
29
|
+
localize = { enabled: true, code: "en-US" }
|
|
30
|
+
) {
|
|
27
31
|
// date-fns doesn't do this automatically
|
|
28
32
|
if ((!showSeconds && seconds < 60) || seconds === 0) {
|
|
29
33
|
return "0 min";
|
|
@@ -41,7 +45,8 @@ function formatDurationLikeMoment(seconds, showSeconds, localize = true) {
|
|
|
41
45
|
};
|
|
42
46
|
const locale = localize
|
|
43
47
|
? {
|
|
44
|
-
|
|
48
|
+
// Maintain backwards compatibility when called with localize=true
|
|
49
|
+
code: localize?.code || "en-US",
|
|
45
50
|
formatDistance: (spec, val) => {
|
|
46
51
|
return `${val} ${specLookup[spec]}`;
|
|
47
52
|
}
|
|
@@ -60,6 +65,22 @@ function formatDurationLikeMoment(seconds, showSeconds, localize = true) {
|
|
|
60
65
|
}
|
|
61
66
|
);
|
|
62
67
|
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Breaks up a duration in seconds into hours, minutes, and seconds.
|
|
71
|
+
* @param {number} seconds The number of seconds to break up
|
|
72
|
+
* @returns an object with fields with the corresponding, hours, minutes, seconds.
|
|
73
|
+
*/
|
|
74
|
+
export function toHoursMinutesSeconds(seconds) {
|
|
75
|
+
const hours = Math.floor(seconds / 3600);
|
|
76
|
+
const minutes = Math.floor((seconds - hours * 3600) / 60);
|
|
77
|
+
return {
|
|
78
|
+
hours,
|
|
79
|
+
minutes,
|
|
80
|
+
seconds: seconds - hours * 3600 - minutes * 60
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
63
84
|
/**
|
|
64
85
|
* @param {[type]} config the OTP config object found in store
|
|
65
86
|
* @return {string} the config-defined time formatter or HH:mm (24-hr time)
|
|
@@ -92,9 +113,18 @@ export function formatDuration(seconds) {
|
|
|
92
113
|
* @param {number} seconds duration in seconds
|
|
93
114
|
* @returns {string} formatted text representation
|
|
94
115
|
*/
|
|
95
|
-
export function formatDurationWithSeconds(seconds) {
|
|
96
|
-
return formatDurationLikeMoment(seconds, true);
|
|
116
|
+
export function formatDurationWithSeconds(seconds, region) {
|
|
117
|
+
return formatDurationLikeMoment(seconds, { enabled: true, code: region });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Offsets a time according to the provided time options
|
|
122
|
+
* and returns the result.
|
|
123
|
+
*/
|
|
124
|
+
export function offsetTime(ms, options) {
|
|
125
|
+
return ms + (options?.offset || 0);
|
|
97
126
|
}
|
|
127
|
+
|
|
98
128
|
/**
|
|
99
129
|
* Formats a time value for display in narrative
|
|
100
130
|
* TODO: internationalization/timezone
|
|
@@ -103,7 +133,7 @@ export function formatDurationWithSeconds(seconds) {
|
|
|
103
133
|
*/
|
|
104
134
|
export function formatTime(ms, options) {
|
|
105
135
|
return format(
|
|
106
|
-
ms
|
|
136
|
+
offsetTime(ms, options),
|
|
107
137
|
options?.format || OTP_API_TIME_FORMAT
|
|
108
138
|
);
|
|
109
139
|
}
|