@opentripplanner/core-utils 4.11.6-alpha.1 → 5.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 (70) hide show
  1. package/esm/deprecated-with-types.js +47 -0
  2. package/esm/deprecated-with-types.js.map +1 -0
  3. package/esm/index.js +0 -4
  4. package/esm/index.js.map +1 -1
  5. package/esm/itinerary.js +1 -1
  6. package/esm/itinerary.js.map +1 -1
  7. package/esm/map.js +16 -8
  8. package/esm/map.js.map +1 -1
  9. package/esm/route.js +5 -3
  10. package/esm/route.js.map +1 -1
  11. package/esm/storage.js +1 -0
  12. package/esm/storage.js.map +1 -1
  13. package/esm/time.js +6 -36
  14. package/esm/time.js.map +1 -1
  15. package/esm/ui.js +1 -1
  16. package/esm/ui.js.map +1 -1
  17. package/lib/deprecated-with-types.d.ts +23 -0
  18. package/lib/deprecated-with-types.d.ts.map +1 -0
  19. package/lib/deprecated-with-types.js +61 -0
  20. package/lib/deprecated-with-types.js.map +1 -0
  21. package/lib/index.d.ts +19 -0
  22. package/lib/index.d.ts.map +1 -0
  23. package/lib/index.js +0 -6
  24. package/lib/index.js.map +1 -1
  25. package/lib/itinerary.d.ts +113 -0
  26. package/lib/itinerary.d.ts.map +1 -0
  27. package/lib/itinerary.js +2 -1
  28. package/lib/itinerary.js.map +1 -1
  29. package/lib/map.d.ts +30 -0
  30. package/lib/map.d.ts.map +1 -0
  31. package/lib/map.js +15 -7
  32. package/lib/map.js.map +1 -1
  33. package/lib/route.d.ts +98 -0
  34. package/lib/route.d.ts.map +1 -0
  35. package/lib/route.js +5 -3
  36. package/lib/route.js.map +1 -1
  37. package/lib/storage.d.ts +19 -0
  38. package/lib/storage.d.ts.map +1 -0
  39. package/lib/storage.js +2 -0
  40. package/lib/storage.js.map +1 -1
  41. package/lib/time.d.ts +65 -0
  42. package/lib/time.d.ts.map +1 -0
  43. package/lib/time.js +22 -39
  44. package/lib/time.js.map +1 -1
  45. package/lib/ui.d.ts +13 -0
  46. package/lib/ui.d.ts.map +1 -0
  47. package/lib/ui.js +1 -1
  48. package/lib/ui.js.map +1 -1
  49. package/package.json +4 -1
  50. package/src/__tests__/__snapshots__/route.js.snap +30 -30
  51. package/src/deprecated-with-types.ts +62 -0
  52. package/src/{index.js → index.ts} +0 -4
  53. package/src/{itinerary.js → itinerary.ts} +70 -36
  54. package/src/{map.js → map.ts} +51 -28
  55. package/src/{route.js → route.ts} +52 -28
  56. package/src/{storage.js → storage.ts} +6 -5
  57. package/src/{time.js → time.ts} +28 -46
  58. package/src/{ui.js → ui.ts} +8 -8
  59. package/tsconfig.json +15 -0
  60. package/tsconfig.tsbuildinfo +4921 -0
  61. package/esm/messages.js +0 -25
  62. package/esm/messages.js.map +0 -1
  63. package/esm/types.js +0 -560
  64. package/esm/types.js.map +0 -1
  65. package/lib/messages.js +0 -29
  66. package/lib/messages.js.map +0 -1
  67. package/lib/types.js +0 -661
  68. package/lib/types.js.map +0 -1
  69. package/src/messages.js +0 -20
  70. package/src/types.js +0 -605
package/lib/time.js CHANGED
@@ -3,24 +3,43 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.formatDurationLikeMoment = formatDurationLikeMoment;
6
7
  exports.toHoursMinutesSeconds = toHoursMinutesSeconds;
7
8
  exports.getTimeFormat = getTimeFormat;
8
9
  exports.getDateFormat = getDateFormat;
9
10
  exports.getLongDateFormat = getLongDateFormat;
10
- exports.formatDuration = formatDuration;
11
- exports.formatDurationWithSeconds = formatDurationWithSeconds;
12
11
  exports.offsetTime = offsetTime;
13
- exports.formatTime = formatTime;
14
12
  exports.formatSecondsAfterMidnight = formatSecondsAfterMidnight;
15
13
  exports.getUserTimezone = getUserTimezone;
16
14
  exports.getCurrentTime = getCurrentTime;
17
15
  exports.getCurrentDate = getCurrentDate;
16
+ Object.defineProperty(exports, "formatTime", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _deprecatedWithTypes.formatTime;
20
+ }
21
+ });
22
+ Object.defineProperty(exports, "formatDurationWithSeconds", {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _deprecatedWithTypes.formatDurationWithSeconds;
26
+ }
27
+ });
28
+ Object.defineProperty(exports, "formatDuration", {
29
+ enumerable: true,
30
+ get: function () {
31
+ return _deprecatedWithTypes.formatDuration;
32
+ }
33
+ });
18
34
  exports.OTP_API_TIME_FORMAT = exports.OTP_API_DATE_FORMAT_DATE_FNS = exports.OTP_API_DATE_FORMAT = void 0;
19
35
 
20
36
  var _dateFns = require("date-fns");
21
37
 
22
38
  var _dateFnsTz = require("date-fns-tz");
23
39
 
40
+ var _deprecatedWithTypes = require("./deprecated-with-types");
41
+
42
+ /* eslint-disable import/no-cycle */
24
43
  // special constants for making sure the following date format is always sent to
25
44
  // OTP regardless of whatever the user has configured as the display format
26
45
  const OTP_API_DATE_FORMAT = "YYYY-MM-DD"; // Date-Fns uses a different string format than moment.js
@@ -114,31 +133,6 @@ function getLongDateFormat(config) {
114
133
 
115
134
  return (config === null || config === void 0 ? void 0 : (_config$dateTime3 = config.dateTime) === null || _config$dateTime3 === void 0 ? void 0 : _config$dateTime3.longDateFormat) || "D MMMM YYYY";
116
135
  }
117
- /**
118
- * Formats an elapsed time duration for display in narrative.
119
- * TODO: internationalization
120
- * @param {number} seconds duration in seconds
121
- * @returns {string} formatted text representation
122
- */
123
-
124
-
125
- function formatDuration(seconds) {
126
- return formatDurationLikeMoment(seconds, false);
127
- }
128
- /**
129
- * Formats an elapsed time in seconds, minutes, hours duration for display in narrative
130
- * @param {number} seconds duration in seconds
131
- * @param {object} region an object that allows internationalization of the time
132
- * @returns {string} formatted text representation
133
- */
134
-
135
-
136
- function formatDurationWithSeconds(seconds, region) {
137
- return formatDurationLikeMoment(seconds, {
138
- enabled: true,
139
- code: region
140
- });
141
- }
142
136
  /**
143
137
  * Offsets a time according to the provided time options
144
138
  * and returns the result.
@@ -148,17 +142,6 @@ function formatDurationWithSeconds(seconds, region) {
148
142
  function offsetTime(ms, options) {
149
143
  return ms + ((options === null || options === void 0 ? void 0 : options.offset) || 0);
150
144
  }
151
- /**
152
- * Formats a time value for display in narrative
153
- * TODO: internationalization/timezone
154
- * @param {number} ms epoch time value in milliseconds
155
- * @returns {string} formatted text representation
156
- */
157
-
158
-
159
- function formatTime(ms, options) {
160
- return (0, _dateFns.format)(offsetTime(ms, options), (options === null || options === void 0 ? void 0 : options.format) || OTP_API_TIME_FORMAT);
161
- }
162
145
  /**
163
146
  * Formats a seconds after midnight value for display in narrative
164
147
  * @param {number} seconds time since midnight in seconds
package/lib/time.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/time.js"],"names":["OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","formatDurationLikeMoment","seconds","showSeconds","localize","enabled","code","hours","Math","floor","minutes","secondsLeftOver","specLookup","xHours","xMinutes","xSeconds","locale","formatDistance","spec","val","undefined","format","toHoursMinutesSeconds","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","formatDuration","formatDurationWithSeconds","region","offsetTime","ms","options","offset","formatTime","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AAMA;;AAEA;AACA;AACO,MAAMA,mBAAmB,GAAG,YAA5B,C,CACP;AACA;;;AACO,MAAMC,4BAA4B,GAAG,YAArC;;AACA,MAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,wBAAT,CACEC,OADF,EAEEC,WAFF,EAGEC,QAAQ,GAAG;AAAEC,EAAAA,OAAO,EAAE,IAAX;AAAiBC,EAAAA,IAAI,EAAE;AAAvB,CAHb,EAIE;AACA;AACA,MAAK,CAACH,WAAD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sFormatDuration\n} from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * To ease the transition away from moment.js, this method uses date-fns to format durations\n * the way moment.js did.\n * @param {number} seconds The number of seconds to format\n * @param {boolean} showSeconds Whether to render seconds or not\n * @param {boolean} localize If true, will create output like moment.js using date-fns locale.\n * Otherwise, uses date-fns default\n * @returns Formatted duration\n */\nfunction formatDurationLikeMoment(\n seconds,\n showSeconds,\n localize = { enabled: true, code: \"en-US\" }\n) {\n // date-fns doesn't do this automatically\n if ((!showSeconds && seconds < 60) || seconds === 0) {\n return \"0 min\";\n }\n\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n const secondsLeftOver = showSeconds\n ? seconds - hours * 3600 - minutes * 60\n : 0;\n const specLookup = {\n xHours: \"hr\",\n xMinutes: \"min\",\n xSeconds: \"sec\"\n };\n const locale = localize\n ? {\n // Maintain backwards compatibility when called with localize=true\n code: localize?.code || \"en-US\",\n formatDistance: (spec, val) => {\n return `${val} ${specLookup[spec]}`;\n }\n }\n : undefined;\n\n return dateFnsFormatDuration(\n {\n hours,\n minutes,\n seconds: secondsLeftOver\n },\n {\n format: [\"hours\", \"minutes\", \"seconds\"],\n locale\n }\n );\n}\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(seconds) {\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n return {\n hours,\n minutes,\n seconds: seconds - hours * 3600 - minutes * 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config) {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config) {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config) {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n\n/**\n * Formats an elapsed time duration for display in narrative.\n * TODO: internationalization\n * @param {number} seconds duration in seconds\n * @returns {string} formatted text representation\n */\nexport function formatDuration(seconds) {\n return formatDurationLikeMoment(seconds, false);\n}\n\n/**\n * Formats an elapsed time in seconds, minutes, hours duration for display in narrative\n * @param {number} seconds duration in seconds\n * @param {object} region an object that allows internationalization of the time\n * @returns {string} formatted text representation\n */\nexport function formatDurationWithSeconds(seconds, region) {\n return formatDurationLikeMoment(seconds, { enabled: true, code: region });\n}\n\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a time value for display in narrative\n * TODO: internationalization/timezone\n * @param {number} ms epoch time value in milliseconds\n * @returns {string} formatted text representation\n */\nexport function formatTime(ms, options) {\n return format(\n offsetTime(ms, options),\n options?.format || OTP_API_TIME_FORMAT\n );\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(seconds, timeFormat) {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\") {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()) {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()) {\n return format(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
1
+ {"version":3,"sources":["../src/time.ts"],"names":["OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","formatDurationLikeMoment","seconds","showSeconds","localize","enabled","code","hours","Math","floor","minutes","secondsLeftOver","specLookup","xHours","xMinutes","xSeconds","locale","formatDistance","spec","val","undefined","format","toHoursMinutesSeconds","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAMA;;AAGA;;AADA;AASA;AACA;AACO,MAAMA,mBAAmB,GAAG,YAA5B,C,CACP;AACA;;;AACO,MAAMC,4BAA4B,GAAG,YAArC;;AACA,MAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASC,wBAAT,CACLC,OADK,EAELC,WAFK,EAGLC,QAA4C,GAAG;AAC7CC,EAAAA,OAAO,EAAE,IADoC;AAE7CC,EAAAA,IAAI,EAAE;AAFuC,CAH1C,EAOG;AACR;AACA,MAAK,CAACH,WAAD,IAAgBD,OAAO,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E,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA7B,EAAqC,OAAOF,OAAO,CAACC,GAAR,CAAYE,EAAnB;AACrC,SAAO,UAAAC,IAAI,UAAJ,sCAAMC,cAAN,GAAuBC,eAAvB,GAAyCC,QAAzC,KAAqDR,gBAA5D;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASS,cAAT,CAAwBC,QAAQ,GAAGX,eAAe,EAAlD,EAA8D;AACnE,SAAO,qBAAO,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CAAP,EAA6CjD,mBAA7C,CAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASmD,cAAT,CAAwBF,QAAQ,GAAGX,eAAe,EAAlD,EAA8D;AACnE,SAAO,qBACL,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CADK,EAELlD,4BAFK,CAAP;AAID","sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport {\n startOfDay,\n add,\n format,\n formatDuration as dateFnsFormatDuration\n} from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n/* eslint-disable import/no-cycle */\nimport {\n formatTime,\n formatDurationWithSeconds,\n formatDuration\n} from \"./deprecated-with-types\";\n\nexport { formatTime, formatDuration, formatDurationWithSeconds };\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * To ease the transition away from moment.js, this method uses date-fns to format durations\n * the way moment.js did.\n * @param {number} seconds The number of seconds to format\n * @param {boolean} showSeconds Whether to render seconds or not\n * @param {boolean} localize If true, will create output like moment.js using date-fns locale.\n * Otherwise, uses date-fns default\n * @returns Formatted duration\n */\nexport function formatDurationLikeMoment(\n seconds: number,\n showSeconds: boolean,\n localize: { enabled: boolean; code: string } = {\n enabled: true,\n code: \"en-US\"\n }\n): string {\n // date-fns doesn't do this automatically\n if ((!showSeconds && seconds < 60) || seconds === 0) {\n return \"0 min\";\n }\n\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n const secondsLeftOver = showSeconds\n ? seconds - hours * 3600 - minutes * 60\n : 0;\n const specLookup = {\n xHours: \"hr\",\n xMinutes: \"min\",\n xSeconds: \"sec\"\n };\n const locale = localize\n ? {\n // Maintain backwards compatibility when called with localize=true\n code: localize?.code || \"en-US\",\n formatDistance: (spec, val) => {\n return `${val} ${specLookup[spec]}`;\n }\n }\n : undefined;\n\n return dateFnsFormatDuration(\n {\n hours,\n minutes,\n seconds: secondsLeftOver\n },\n {\n format: [\"hours\", \"minutes\", \"seconds\"],\n locale\n }\n );\n}\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(seconds) {\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n return {\n hours,\n minutes,\n seconds: seconds - hours * 3600 - minutes * 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
package/lib/ui.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export declare function isMobile(): boolean;
2
+ /**
3
+ * Returns true if the user is using a [redacted] browser
4
+ */
5
+ export declare function isIE(): boolean;
6
+ /**
7
+ * Enables scrolling for a specified selector, while disabling scrolling for all
8
+ * other targets. This is adapted from https://stackoverflow.com/a/41601290/915811
9
+ * and intended to fix issues with iOS elastic scrolling, e.g.,
10
+ * https://github.com/conveyal/trimet-mod-otp/issues/92.
11
+ */
12
+ export declare function enableScrollForSelector(selector: string): void;
13
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,IAAI,OAAO,CAKlC;AAED;;GAEG;AACH,wBAAgB,IAAI,IAAI,OAAO,CAE9B;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CA4C9D"}
package/lib/ui.js CHANGED
@@ -21,7 +21,7 @@ function isMobile() {
21
21
 
22
22
 
23
23
  function isIE() {
24
- return _bowser.default.name === "Internet Explorer";
24
+ return _bowser.default.parse(navigator.userAgent).browser === "Internet Explorer";
25
25
  }
26
26
  /**
27
27
  * Enables scrolling for a specified selector, while disabling scrolling for all
package/lib/ui.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ui.js"],"names":["isMobile","test","navigator","userAgent","isIE","bowser","name","enableScrollForSelector","selector","overlay","document","querySelector","clientY","isOverlayTotallyScrolled","scrollHeight","scrollTop","clientHeight","disableRubberBand","event","clientYDelta","targetTouches","preventDefault","addEventListener","length"],"mappings":";;;;;;;;;;;AAAA;;AAEO,SAASA,QAAT,GAAoB;AACzB;AACA,SAAO,iEAAiEC,IAAjE,CACLC,SAAS,CAACC,SADL,CAAP;AAGD;AAED;AACA;AACA;;;AACO,SAASC,IAAT,GAAgB;AACrB,SAAOC,gBAAOC,IAAP,KAAgB,mBAAvB;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,uBAAT,CAAiCC,QAAjC,EAA2C;AAChD,QAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAT,CAAuBH,QAAvB,CAAhB;AACA,MAAII,OAAO,GAAG,IAAd,CAFgD,CAE5B;;AAEpB,WAASC,wBAAT,GAAoC;AAClC;AACA,WAAOJ,OAAO,CAACK,YAAR,GAAuBL,OAAO,CAACM,SAA/B,IAA4CN,OAAO,CAACO,YAA3D;AACD;;AAED,WAASC,iBAAT,CAA2BC,KAA3B,EAAkC;AAChC,UAAMC,YAAY,GAAGD,KAAK,CAACE,aAAN,CAAoB,CAApB,EAAuBR,OAAvB,GAAiCA,OAAtD;;AAEA,QAAIH,OAAO,CAACM,SAAR,KAAsB,CAAtB,IAA2BI,YAAY,GAAG,CAA9C,EAAiD;AAC/C;AACAD,MAAAA,KAAK,CAACG,cAAN;AACD;;AAED,QAAIR,wBAAwB,MAAMM,YAAY,GAAG,CAAjD,EAAoD;AAClD;AACAD,MAAAA,KAAK,CAACG,cAAN;AACD;AACF;;AAEDZ,EAAAA,OAAO,CAACa,gBAAR,CACE,YADF,EAEE,UAASJ,KAAT,EAAgB;AACd,QAAIA,KAAK,CAACE,aAAN,CAAoBG,MAApB,KAA+B,CAAnC,EAAsC;AACpC;AACAX,MAAAA,OAAO,GAAGM,KAAK,CAACE,aAAN,CAAoB,CAApB,EAAuBR,OAAjC;AACD;AACF,GAPH,EAQE,KARF;AAWAH,EAAAA,OAAO,CAACa,gBAAR,CACE,WADF,EAEE,UAASJ,KAAT,EAAgB;AACd,QAAIA,KAAK,CAACE,aAAN,CAAoBG,MAApB,KAA+B,CAAnC,EAAsC;AACpC;AACAN,MAAAA,iBAAiB,CAACC,KAAD,CAAjB;AACD;AACF,GAPH,EAQE,KARF;AAUD","sourcesContent":["import bowser from \"bowser\";\n\nexport function isMobile() {\n // TODO: consider using 3rd-party library?\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(\n navigator.userAgent\n );\n}\n\n/**\n * Returns true if the user is using a [redacted] browser\n */\nexport function isIE() {\n return bowser.name === \"Internet Explorer\";\n}\n\n/**\n * Enables scrolling for a specified selector, while disabling scrolling for all\n * other targets. This is adapted from https://stackoverflow.com/a/41601290/915811\n * and intended to fix issues with iOS elastic scrolling, e.g.,\n * https://github.com/conveyal/trimet-mod-otp/issues/92.\n */\nexport function enableScrollForSelector(selector) {\n const overlay = document.querySelector(selector);\n let clientY = null; // remember Y position on touch start\n\n function isOverlayTotallyScrolled() {\n // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions\n return overlay.scrollHeight - overlay.scrollTop <= overlay.clientHeight;\n }\n\n function disableRubberBand(event) {\n const clientYDelta = event.targetTouches[0].clientY - clientY;\n\n if (overlay.scrollTop === 0 && clientYDelta > 0) {\n // element is at the top of its scroll\n event.preventDefault();\n }\n\n if (isOverlayTotallyScrolled() && clientYDelta < 0) {\n // element is at the top of its scroll\n event.preventDefault();\n }\n }\n\n overlay.addEventListener(\n \"touchstart\",\n function(event) {\n if (event.targetTouches.length === 1) {\n // detect single touch\n clientY = event.targetTouches[0].clientY;\n }\n },\n false\n );\n\n overlay.addEventListener(\n \"touchmove\",\n function(event) {\n if (event.targetTouches.length === 1) {\n // detect single touch\n disableRubberBand(event);\n }\n },\n false\n );\n}\n"],"file":"ui.js"}
1
+ {"version":3,"sources":["../src/ui.ts"],"names":["isMobile","test","navigator","userAgent","isIE","bowser","parse","browser","enableScrollForSelector","selector","overlay","document","querySelector","clientY","isOverlayTotallyScrolled","scrollHeight","scrollTop","clientHeight","disableRubberBand","event","clientYDelta","targetTouches","preventDefault","addEventListener","length"],"mappings":";;;;;;;;;;;AAAA;;AAEO,SAASA,QAAT,GAA6B;AAClC;AACA,SAAO,iEAAiEC,IAAjE,CACLC,SAAS,CAACC,SADL,CAAP;AAGD;AAED;AACA;AACA;;;AACO,SAASC,IAAT,GAAyB;AAC9B,SAAOC,gBAAOC,KAAP,CAAaJ,SAAS,CAACC,SAAvB,EAAkCI,OAAlC,KAA8C,mBAArD;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,uBAAT,CAAiCC,QAAjC,EAAyD;AAC9D,QAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAT,CAAuBH,QAAvB,CAAhB;AACA,MAAII,OAAO,GAAG,IAAd,CAF8D,CAE1C;;AAEpB,WAASC,wBAAT,GAA6C;AAC3C;AACA,WAAOJ,OAAO,CAACK,YAAR,GAAuBL,OAAO,CAACM,SAA/B,IAA4CN,OAAO,CAACO,YAA3D;AACD;;AAED,WAASC,iBAAT,CAA2BC,KAA3B,EAA8C;AAC5C,UAAMC,YAAY,GAAGD,KAAK,CAACE,aAAN,CAAoB,CAApB,EAAuBR,OAAvB,GAAiCA,OAAtD;;AAEA,QAAIH,OAAO,CAACM,SAAR,KAAsB,CAAtB,IAA2BI,YAAY,GAAG,CAA9C,EAAiD;AAC/C;AACAD,MAAAA,KAAK,CAACG,cAAN;AACD;;AAED,QAAIR,wBAAwB,MAAMM,YAAY,GAAG,CAAjD,EAAoD;AAClD;AACAD,MAAAA,KAAK,CAACG,cAAN;AACD;AACF;;AAEDZ,EAAAA,OAAO,CAACa,gBAAR,CACE,YADF,EAEE,UAASJ,KAAT,EAA4B;AAC1B,QAAIA,KAAK,CAACE,aAAN,CAAoBG,MAApB,KAA+B,CAAnC,EAAsC;AACpC;AACAX,MAAAA,OAAO,GAAGM,KAAK,CAACE,aAAN,CAAoB,CAApB,EAAuBR,OAAjC;AACD;AACF,GAPH,EAQE,KARF;AAWAH,EAAAA,OAAO,CAACa,gBAAR,CACE,WADF,EAEE,UAASJ,KAAT,EAA4B;AAC1B,QAAIA,KAAK,CAACE,aAAN,CAAoBG,MAApB,KAA+B,CAAnC,EAAsC;AACpC;AACAN,MAAAA,iBAAiB,CAACC,KAAD,CAAjB;AACD;AACF,GAPH,EAQE,KARF;AAUD","sourcesContent":["import bowser from \"bowser\";\n\nexport function isMobile(): boolean {\n // TODO: consider using 3rd-party library?\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(\n navigator.userAgent\n );\n}\n\n/**\n * Returns true if the user is using a [redacted] browser\n */\nexport function isIE(): boolean {\n return bowser.parse(navigator.userAgent).browser === \"Internet Explorer\";\n}\n\n/**\n * Enables scrolling for a specified selector, while disabling scrolling for all\n * other targets. This is adapted from https://stackoverflow.com/a/41601290/915811\n * and intended to fix issues with iOS elastic scrolling, e.g.,\n * https://github.com/conveyal/trimet-mod-otp/issues/92.\n */\nexport function enableScrollForSelector(selector: string): void {\n const overlay = document.querySelector(selector);\n let clientY = null; // remember Y position on touch start\n\n function isOverlayTotallyScrolled(): boolean {\n // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions\n return overlay.scrollHeight - overlay.scrollTop <= overlay.clientHeight;\n }\n\n function disableRubberBand(event: TouchEvent) {\n const clientYDelta = event.targetTouches[0].clientY - clientY;\n\n if (overlay.scrollTop === 0 && clientYDelta > 0) {\n // element is at the top of its scroll\n event.preventDefault();\n }\n\n if (isOverlayTotallyScrolled() && clientYDelta < 0) {\n // element is at the top of its scroll\n event.preventDefault();\n }\n }\n\n overlay.addEventListener(\n \"touchstart\",\n function(event: TouchEvent) {\n if (event.targetTouches.length === 1) {\n // detect single touch\n clientY = event.targetTouches[0].clientY;\n }\n },\n false\n );\n\n overlay.addEventListener(\n \"touchmove\",\n function(event: TouchEvent) {\n if (event.targetTouches.length === 1) {\n // detect single touch\n disableRubberBand(event);\n }\n },\n false\n );\n}\n"],"file":"ui.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentripplanner/core-utils",
3
- "version": "4.11.6-alpha.1",
3
+ "version": "5.0.1",
4
4
  "description": "Core functionality that is shared among numerous UI components",
5
5
  "engines": {
6
6
  "node": ">=13"
@@ -26,5 +26,8 @@
26
26
  "qs": "^6.9.1"
27
27
  },
28
28
  "gitHead": "0af1b7cda60bd4252b219dcf893e01c2acb2ed5d",
29
+ "scripts": {
30
+ "tsc": "tsc"
31
+ },
29
32
  "devDependencies": {}
30
33
  }
@@ -35,18 +35,18 @@ Array [
35
35
 
36
36
  exports[`util > route routeComparator should prioritize routes with valid sortOrder 1`] = `
37
37
  Array [
38
- Object {
39
- "longName": "Around town",
40
- "mode": "BUS",
41
- "shortName": "20",
42
- "sortOrder": 2,
43
- },
44
38
  Object {
45
39
  "longName": "Around another town",
46
40
  "shortName": "3",
47
41
  "sortOrder": -999,
48
42
  "type": 3,
49
43
  },
44
+ Object {
45
+ "longName": "Around town",
46
+ "mode": "BUS",
47
+ "shortName": "20",
48
+ "sortOrder": 2,
49
+ },
50
50
  ]
51
51
  `;
52
52
 
@@ -191,6 +191,30 @@ Array [
191
191
  "shortName": "IC",
192
192
  "sortOrder": 2,
193
193
  },
194
+ Object {
195
+ "longName": "A-line",
196
+ "mode": "BUS",
197
+ "shortName": "A",
198
+ "sortOrder": -999,
199
+ },
200
+ Object {
201
+ "longName": "B-line",
202
+ "mode": "BUS",
203
+ "shortName": "B",
204
+ "sortOrder": -999,
205
+ },
206
+ Object {
207
+ "longName": "Loop route",
208
+ "mode": "BUS",
209
+ "shortName": "2",
210
+ "sortOrder": -999,
211
+ },
212
+ Object {
213
+ "longName": "Around another town",
214
+ "shortName": "3",
215
+ "sortOrder": -999,
216
+ "type": 3,
217
+ },
194
218
  Object {
195
219
  "longName": "Local route",
196
220
  "mode": "BUS",
@@ -239,30 +263,6 @@ Array [
239
263
  "shortName": "10",
240
264
  "sortOrder": 10,
241
265
  },
242
- Object {
243
- "longName": "A-line",
244
- "mode": "BUS",
245
- "shortName": "A",
246
- "sortOrder": -999,
247
- },
248
- Object {
249
- "longName": "B-line",
250
- "mode": "BUS",
251
- "shortName": "B",
252
- "sortOrder": -999,
253
- },
254
- Object {
255
- "longName": "Loop route",
256
- "mode": "BUS",
257
- "shortName": "2",
258
- "sortOrder": -999,
259
- },
260
- Object {
261
- "longName": "Around another town",
262
- "shortName": "3",
263
- "sortOrder": -999,
264
- "type": 3,
265
- },
266
266
  Object {
267
267
  "longName": "A meandering route",
268
268
  "mode": "BUS",
@@ -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
+ }
@@ -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