@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
package/lib/route.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/route.js"],"names":["getTransitOperatorFromFeedIdAndAgencyId","feedId","agencyId","transitOperators","find","transitOperator","getTransitOperatorFromLeg","leg","routeId","split","getTransitOperatorFromOtpRoute","route","id","agency","END_OF_LIST_COMPARATOR_VALUE","getTransitOperatorComparatorValue","length","name","agencyName","order","makeTransitOperatorComparator","a","b","aVal","bVal","getSortValues","getterFn","modeComparatorValue","SUBWAY","TRAM","RAIL","GONDOLA","FERRY","CABLE_CAR","FUNICULAR","BUS","routeTypeComparatorValue","getRouteTypeComparatorValue","Error","mode","type","console","warn","routeTypeComparator","startsWithAlphabeticCharacter","val","firstCharCode","charCodeAt","alphabeticShortNameComparator","aStartsWithAlphabeticCharacter","shortName","bStartsWithAlphabeticCharacter","makeNumericValueComparator","objGetterFn","isNaN","makeStringValueComparator","getRouteSortOrderValue","undefined","makeMultiCriteriaSort","criteria","i","curCriteriaComparatorValue","makeRouteComparator","obj","sortOrder","parseInt","longName"],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uCAAT,CACLC,MADK,EAELC,QAFK,EAGLC,gBAHK,EAIL;AACA,SACEA,gBAAgB,CAACC,IAAjB,CACEC,eAAe,IACbA,eAAe,CAACJ,MAAhB,KAA2BA,MAA3B,IACAI,eAAe,CAACH,QAAhB,KAA6BA,QAHjC,KAIK,IALP;AAOD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,yBAAT,CAAmCC,GAAnC,EAAwCJ,gBAAxC,EAA0D;AAC/D,MAAI,CAACI,GAAG,CAACC,OAAL,IAAgB,CAACD,GAAG,CAACL,QAAzB,EAAmC,OAAO,IAAP;AACnC,QAAMD,MAAM,GAAGM,GAAG,CAACC,OAAJ,CAAYC,KAAZ,CAAkB,GAAlB,EAAuB,CAAvB,CAAf;AACA,SAAOT,uCAAuC,CAC5CC,MAD4C,EAE5CM,GAAG,CAACL,QAFwC,EAG5CC,gBAH4C,CAA9C;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,8BAAT,CAAwCC,KAAxC,EAA+CR,gBAA/C,EAAiE;AACtE,MAAI,CAACQ,KAAK,CAACC,EAAX,EAAe,OAAO,IAAP;AACf,QAAMX,MAAM,GAAGU,KAAK,CAACC,EAAN,CAASH,KAAT,CAAe,GAAf,EAAoB,CAApB,CA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,CAAnC,EAAsC;AACpC,eAAOA,0BAAP;AACD;AACF;;AACD,WAAO,CAAP;AACD,GAVD;AAWD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,CAA6B3D,gBAA7B,EAA+C;AACpD,SAAOuD,qBAAqB,CAC1BtC,6BAA6B,CAACjB,gBAAD,CADH,EAE1BiD,0BAA0B,CAACW,GAAG,IAAIP,sBAAsB,CAACO,GAAG,CAACC,SAAL,CAA9B,CAFA,EAG1BrB,mBAH0B,EAI1BK,6BAJ0B,EAK1BI,0BAA0B,CAACW,GAAG,IAAIE,QAAQ,CAACF,GAAG,CAACb,SAAL,EAAgB,EAAhB,CAAhB,CALA,EAM1BK,yBAAyB,CAACQ,GAAG,IAAIA,GAAG,CAACb,SAAZ,CANC,EAO1BK,yBAAyB,CAACQ,GAAG,IAAIA,GAAG,CAACG,QAAZ,CAPC,CAA5B;AASD","sourcesContent":["/**\n * Returns the transit operator (if an exact match is found) from the transit\n * operators config value. It is critical to use both the feedId and agencyId in\n * this method because it is possible in OTP for there to be a duplicate\n * agencyId in separate feeds.\n *\n * @param {string} feedId The feedId that this transit agency belongs to\n * @param {string} agencyId The agencyId of the transit agency\n * @param {array} transitOperators The transitOperators list from the config\n * @return {object} The transitOperator if a match was found or null if no match\n * was found\n */\nexport function getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n) {\n return (\n transitOperators.find(\n transitOperator =>\n transitOperator.feedId === feedId &&\n transitOperator.agencyId === agencyId\n ) || null\n );\n}\n\n/**\n * Looks up an operator from the provided leg.\n *\n * @param {object} leg The Itinerary Leg from which to find the transit\n * operator\n * @param {object} transitOperators transitOperators from config.\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromLeg(leg, transitOperators) {\n if (!leg.routeId || !leg.agencyId) return null;\n const feedId = leg.routeId.split(\":\")[0];\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n leg.agencyId,\n transitOperators\n );\n}\n\n/**\n * Looks up an operator from the provided configuration given an OTP route.\n * NOTE: this assumes the use of the OTP Route model or a modified OTP\n * RouteShort model (such as the one found in the IBI fork of OTP) that also\n * returns the agencyId.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromOtpRoute(route, transitOperators) {\n if (!route.id) return null;\n const feedId = route.id.split(\":\")[0];\n let agencyId;\n if (route.agency) {\n // This is returned in the OTP Route model\n agencyId = route.agency.id;\n } else if (route.agencyId) {\n // This is returned in the OTP RouteShort model (such as in the IBI fork)\n agencyId = route.agencyId;\n } else {\n return null;\n }\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n );\n}\n\n// The functions below are for enhanced route sorting functions for the route\n// viewer on OTP-react-redux.\n// They address route ordering issues discussed in\n// https://github.com/opentripplanner/otp-react-redux/pull/123 and\n// https://github.com/opentripplanner/otp-react-redux/pull/124.\n\n/**\n * A large comparator value that can safely be used in mathematical sort\n * comparisons to place things at the end of lists\n */\nconst END_OF_LIST_COMPARATOR_VALUE = 999999999999;\n\n/**\n * Returns a transit operator comparator value given a route and an optional\n * transitOperators config value. This function will do its best to handle all\n * kinds of input data as certain deployments of an implementing webapp may have\n * incomplete data and certain versions of OTP might not have a modified\n * implementation of the RouteShort model.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {mixed} this could return a string value (the route's agency name) if\n * the transitOperators value is not defined. Otherwise an integer will be\n * returned.\n */\nfunction getTransitOperatorComparatorValue(route, transitOperators) {\n // if the transitOperators is undefined or has zero length, use the route's\n // agency name as the comparator value\n if (!transitOperators || transitOperators.length === 0) {\n // OTP Route\n if (route.agency) return route.agency.name;\n // OTP RouteShort (base OTP repo or IBI fork)\n if (route.agencyName) return route.agencyName;\n // shouldn't happen as agency names will be defined\n return \"zzz\";\n }\n\n // find operator associated with route\n const transitOperator = getTransitOperatorFromOtpRoute(\n route,\n transitOperators\n );\n\n // if transit operator not found, return infinity\n if (!transitOperator) return END_OF_LIST_COMPARATOR_VALUE;\n\n // return the transit operator's sort value or END_OF_LIST_COMPARATOR_VALUE if\n // the sort value is not a number\n return typeof transitOperator.order === \"number\"\n ? transitOperator.order\n : END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of the\n * route's agency and provided transitOperators config data.\n */\nfunction makeTransitOperatorComparator(transitOperators) {\n return (a, b) => {\n const aVal = getTransitOperatorComparatorValue(a, transitOperators);\n const bVal = getTransitOperatorComparatorValue(b, transitOperators);\n if (typeof aVal === \"string\") {\n // happens when transitOperators is undefined. Both aVal are guaranteed to\n // be strings. Make a string comparison.\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n }\n\n // transitOperators are defined and therefore a numeric value is guaranteed\n // to be returned\n return aVal - bVal;\n };\n}\n\n/**\n * Gets the desired sort values according to an optional getter function. If the\n * getter function is not defined, the original sort values are returned.\n */\nfunction getSortValues(getterFn, a, b) {\n let aVal;\n let bVal;\n if (typeof getterFn === \"function\") {\n aVal = getterFn(a);\n bVal = getterFn(b);\n } else {\n aVal = a;\n bVal = b;\n }\n return { aVal, bVal };\n}\n\n// Lookup for the sort values associated with various OTP modes.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst modeComparatorValue = {\n SUBWAY: 1,\n TRAM: 2,\n RAIL: 3,\n GONDOLA: 4,\n FERRY: 5,\n CABLE_CAR: 6,\n FUNICULAR: 7,\n BUS: 8\n};\n\n// Lookup that maps route types to the OTP mode sort values.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst routeTypeComparatorValue = {\n 0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.\n 1: modeComparatorValue.SUBWAY, // - Subway, Metro.\n 2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.\n 3: modeComparatorValue.BUS, // - Bus.\n 4: modeComparatorValue.FERRY, // - Ferry.\n 5: modeComparatorValue.CABLE_CAR, // - Cable tram.\n 6: modeComparatorValue.GONDOLA, // - Gondola, etc.\n 7: modeComparatorValue.FUNICULAR, // - Funicular.\n // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just\n // associate them with bus/rail.\n 11: modeComparatorValue.BUS, // - Trolleybus.\n 12: modeComparatorValue.RAIL // - Monorail.\n};\n\n// Gets a comparator value for a given route's type (OTP mode).\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// ttps://github.com/documentationjs/documentation/issues/372\nfunction getRouteTypeComparatorValue(route) {\n // For some strange reason, the short route response in OTP returns the\n // string-based modes, but the long route response returns the\n // integer route type. This attempts to account for both of those cases.\n if (!route) throw new Error(\"Route is undefined.\", route);\n if (typeof modeComparatorValue[route.mode] !== \"undefined\") {\n return modeComparatorValue[route.mode];\n }\n if (typeof routeTypeComparatorValue[route.type] !== \"undefined\") {\n return routeTypeComparatorValue[route.type];\n }\n // Default the comparator value to a large number (placing the route at the\n // end of the list).\n console.warn(\"no mode/route type found for route\", route);\n return END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of route type\n * (OTP mode).\n */\nfunction routeTypeComparator(a, b) {\n return getRouteTypeComparatorValue(a) - getRouteTypeComparatorValue(b);\n}\n\n/**\n * Determines whether a value is a string that starts with an alphabetic\n * ascii character.\n */\nfunction startsWithAlphabeticCharacter(val) {\n if (typeof val === \"string\" && val.length > 0) {\n const firstCharCode = val.charCodeAt(0);\n return (\n (firstCharCode >= 65 && firstCharCode <= 90) ||\n (firstCharCode >= 97 && firstCharCode <= 122)\n );\n }\n return false;\n}\n\n/**\n * Sorts routes based off of whether the shortName begins with an alphabetic\n * character. Routes with shortn that do start with an alphabetic character will\n * be prioritized over those that don't.\n */\nfunction alphabeticShortNameComparator(a, b) {\n const aStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n a.shortName\n );\n const bStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n b.shortName\n );\n\n if (aStartsWithAlphabeticCharacter && bStartsWithAlphabeticCharacter) {\n // both start with an alphabetic character, return equivalence\n return 0;\n }\n // a does start with an alphabetic character, but b does not. Prioritize a\n if (aStartsWithAlphabeticCharacter) return -1;\n // b does start with an alphabetic character, but a does not. Prioritize b\n if (bStartsWithAlphabeticCharacter) return 1;\n // neither route has a shortName that starts with an alphabetic character.\n // Return equivalence\n return 0;\n}\n\n/**\n * Checks whether an appropriate comparison of numeric values can be made for\n * sorting purposes. If both values are not valid numbers according to the\n * isNaN check, then this function returns undefined which indicates that a\n * secondary sorting criteria should be used instead. If one value is valid and\n * the other is not, then the valid value will be given sorting priority. If\n * both values are valid numbers, the difference is obtained as the sort value.\n *\n * An optional argument can be provided which will be used to obtain the\n * comparison value from the comparison function arguments.\n *\n * IMPORTANT: the comparison values must be numeric values or at least be\n * attempted to be converted to numeric values! If one of the arguments is\n * something crazy like an empty string, unexpected behavior will occur because\n * JavaScript.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeNumericValueComparator(objGetterFn) {\n /* Note: Using the global version of isNaN (the Number version behaves differently. */\n /* eslint-disable no-restricted-globals */\n return (a, b) => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // if both values aren't valid numbers, use the next sort criteria\n if (isNaN(aVal) && isNaN(bVal)) return 0;\n // b is a valid number, b gets priority\n if (isNaN(aVal)) return 1;\n // a is a valid number, a gets priority\n if (isNaN(bVal)) return -1;\n // a and b are valid numbers, return the sort value\n return aVal - bVal;\n };\n}\n\n/**\n * Create a comparator function that compares string values. The comparison\n * values feed to the sort comparator function are assumed to be objects that\n * will have either undefined, null or string values at the given key. If one\n * object has undefined, null or an empty string, but the other does have a\n * string with length > 0, then that string will get priority.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeStringValueComparator(objGetterFn) {\n return (a, b) => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // both a and b are uncomparable strings, return equivalent value\n if (!aVal && !bVal) return 0;\n // a is not a comparable string, b gets priority\n if (!aVal) return 1;\n // b is not a comparable string, a gets priority\n if (!bVal) return -1;\n // a and b are comparable strings, return the sort value\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n };\n}\n\n/**\n * OpenTripPlanner sets the routeSortOrder to -999 by default. So, if that value\n * is encountered, assume that it actually means that the routeSortOrder is not\n * set in the GTFS.\n *\n * See https://github.com/opentripplanner/OpenTripPlanner/issues/2938\n * Also see https://github.com/opentripplanner/otp-react-redux/issues/122\n */\nfunction getRouteSortOrderValue(val) {\n return val === -999 ? undefined : val;\n}\n\n/**\n * Create a multi-criteria sort comparator function composed of other sort\n * comparator functions. Each comparator function will be ran in the order given\n * until a non-zero comparison value is obtained which is then immediately\n * returned. If all comparison functions return equivalence, then the values\n * are assumed to be equivalent.\n */\nfunction makeMultiCriteriaSort(...criteria) {\n return (a, b) => {\n for (let i = 0; i < criteria.length; i++) {\n const curCriteriaComparatorValue = criteria[i](a, b);\n // if the comparison objects are not equivalent, return the value obtained\n // in this current criteria comparison\n if (curCriteriaComparatorValue !== 0) {\n return curCriteriaComparatorValue;\n }\n }\n return 0;\n };\n}\n\n/**\n * Creates a sort comparator function to compares routes for the purposes of\n * sorting and displaying in a user interface. This takes in a single optional\n * argument which should be a list of transitOperators as defined in the config\n * file. Due to GTFS feeds having varying levels of data quality, a multi-\n * criteria sort is needed to account for various differences. The criteria\n * included here are each applied to the routes in the order listed. If a given\n * sort criterion yields equivalence (e.g., two routes have the short name\n * \"20\"), the comparator falls back onto the next sort criterion (e.g., long\n * name). The sort operates on the following values (in order):\n *\n * 1. Transit Operator. The transit operator will be attempted to be obtained\n * for each route. If no argument is provided when creating this comparator\n * function, then routes will be sorted by their agency's name. If an\n * argument is provided and a match is found based off of the route's feed_id\n * and agency_id and a transitOperator's feed_id and agency_id, then the\n * field transitOperator.order will be used as the comparator value as long\n * as it is numeric. If it is not numeric, a value is returned indicating\n * that this transit operator should be placed at the end of the list.\n * 2. sortOrder. Routes that do not have a valid sortOrder will be placed\n * beneath those that do.\n * 3. route type (OTP mode). See routeTypeComparator code for prioritization of\n * route types.\n * 4. shortNames that begin with alphabetic characters. shortNames that do not\n * start with alphabetic characters will be place beneath those that do.\n * 5. shortName as integer. shortNames that cannot be parsed as integers will\n * be placed beneath those that are valid.\n * 6. shortName as string. Routes without shortNames will be placed beneath\n * those with shortNames.\n * 7. longName as string.\n */\nexport function makeRouteComparator(transitOperators) {\n return makeMultiCriteriaSort(\n makeTransitOperatorComparator(transitOperators),\n makeNumericValueComparator(obj => getRouteSortOrderValue(obj.sortOrder)),\n routeTypeComparator,\n alphabeticShortNameComparator,\n makeNumericValueComparator(obj => parseInt(obj.shortName, 10)),\n makeStringValueComparator(obj => obj.shortName),\n makeStringValueComparator(obj => obj.longName)\n );\n}\n"],"file":"route.js"}
1
+ {"version":3,"sources":["../src/route.ts"],"names":["getTransitOperatorFromFeedIdAndAgencyId","feedId","agencyId","transitOperators","find","transitOperator","getTransitOperatorFromLeg","leg","routeId","split","getTransitOperatorFromOtpRoute","route","id","agency","END_OF_LIST_COMPARATOR_VALUE","getTransitOperatorComparatorValue","length","name","agencyName","order","makeTransitOperatorComparator","a","b","aVal","bVal","getSortValues","getterFn","modeComparatorValue","SUBWAY","TRAM","RAIL","GONDOLA","FERRY","CABLE_CAR","FUNICULAR","BUS","routeTypeComparatorValue","getRouteTypeComparatorValue","Error","mode","type","console","warn","routeTypeComparator","startsWithAlphabeticCharacter","val","firstCharCode","charCodeAt","alphabeticShortNameComparator","aStartsWithAlphabeticCharacter","shortName","bStartsWithAlphabeticCharacter","makeNumericValueComparator","objGetterFn","isNaN","makeStringValueComparator","getRouteSortOrderValue","undefined","makeMultiCriteriaSort","criteria","i","curCriteriaComparatorValue","makeRouteComparator","obj","sortOrder","parseInt","longName"],"mappings":";;;;;;;;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uCAAT,CACLC,MADK,EAELC,QAFK,EAGLC,gBAHK,EAIY;AACjB,SACEA,gBAAgB,CAACC,IAAjB,CACEC,eAAe,IACbA,eAAe,CAACJ,MAAhB,KAA2BA,MAA3B,IACAI,eAAe,CAACH,QAAhB,KAA6BA,QAHjC,KAIK,IALP;AAOD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,yBAAT,CACLC,GADK,EAELJ,gBAFK,EAGY;AACjB,MAAI,CAACI,GAAG,CAACC,OAAL,IAAgB,CAACD,GAAG,CAACL,QAAzB,EAAmC,OAAO,IAAP;AACnC,QAAMD,MAAM,GAAGM,GAAG,CAACC,OAAJ,CAAYC,KAAZ,CAAkB,GAAlB,EAAuB,CAAvB,CAAf;AACA,SAAOT,uCAAuC,CAC5CC,MAD4C,EAE5CM,GAAG,CAACL,QAFwC,EAG5CC,gBAH4C,CAA9C;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,8BAAT,CACLC,KADK,EAELR,gBAFK,EAGY;AACjB,MAAI,CAACQ,KAAK,CAACC,EAAX,EAAe,OAAO,IAAP;AACf,QAAMX,MAAM,GAAGU,KAAK,CAACC,EAAN,CAASH,KAAT,CAAe,GAAf,EAAoB,CAApB,CAAf;AACA,MAAIP,QAAJ;;AACA,MAAIS,KAAK,CAACE,MAAV,EAAkB;AAChB;AACAX,IAAAA,QAAQ,GAAGS,KAAK,CAACE,MAAN,CAAaD,EAAxB;AACD,GAHD,MAGO,IAAID,KAAK,CAACT,QAAV,EAAoB;AACzB;AACAA,IAAAA,QAAQ,GAAGS,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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,CACL3D,gBADK,EAE6B;AAClC,SAAOuD,qBAAqB,CAC1BtC,6BAA6B,CAACjB,gBAAD,CADH,EAE1BiD,0BAA0B,CAACW,GAAG,IAAIP,sBAAsB,CAACO,GAAG,CAACC,SAAL,CAA9B,CAFA,EAG1BrB,mBAH0B,EAI1BK,6BAJ0B,EAK1BI,0BAA0B,CAACW,GAAG,IAAIE,QAAQ,CAACF,GAAG,CAACb,SAAL,EAAgB,EAAhB,CAAhB,CALA,EAM1BK,yBAAyB,CAACQ,GAAG,IAAIA,GAAG,CAACb,SAAZ,CANC,EAO1BK,yBAAyB,CAACQ,GAAG,IAAIA,GAAG,CAACG,QAAZ,CAPC,CAA5B;AASD","sourcesContent":["import { Leg, Route, TransitOperator } from \"@opentripplanner/types\";\n/**\n * Returns the transit operator (if an exact match is found) from the transit\n * operators config value. It is critical to use both the feedId and agencyId in\n * this method because it is possible in OTP for there to be a duplicate\n * agencyId in separate feeds.\n *\n * @param {string} feedId The feedId that this transit agency belongs to\n * @param {string} agencyId The agencyId of the transit agency\n * @param {array} transitOperators The transitOperators list from the config\n * @return {object} The transitOperator if a match was found or null if no match\n * was found\n */\nexport function getTransitOperatorFromFeedIdAndAgencyId(\n feedId: string,\n agencyId: string | number,\n transitOperators: TransitOperator[]\n): TransitOperator {\n return (\n transitOperators.find(\n transitOperator =>\n transitOperator.feedId === feedId &&\n transitOperator.agencyId === agencyId\n ) || null\n );\n}\n\n/**\n * Looks up an operator from the provided leg.\n *\n * @param {object} leg The Itinerary Leg from which to find the transit\n * operator\n * @param {object} transitOperators transitOperators from config.\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromLeg(\n leg: Leg,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!leg.routeId || !leg.agencyId) return null;\n const feedId = leg.routeId.split(\":\")[0];\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n leg.agencyId,\n transitOperators\n );\n}\n\n/**\n * Looks up an operator from the provided configuration given an OTP route.\n * NOTE: this assumes the use of the OTP Route model or a modified OTP\n * RouteShort model (such as the one found in the IBI fork of OTP) that also\n * returns the agencyId.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromOtpRoute(\n route: Route,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!route.id) return null;\n const feedId = route.id.split(\":\")[0];\n let agencyId: string | number;\n if (route.agency) {\n // This is returned in the OTP Route model\n agencyId = route.agency.id;\n } else if (route.agencyId) {\n // This is returned in the OTP RouteShort model (such as in the IBI fork)\n agencyId = route.agencyId;\n } else {\n return null;\n }\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n );\n}\n\n// The functions below are for enhanced route sorting functions for the route\n// viewer on OTP-react-redux.\n// They address route ordering issues discussed in\n// https://github.com/opentripplanner/otp-react-redux/pull/123 and\n// https://github.com/opentripplanner/otp-react-redux/pull/124.\n\n/**\n * A large comparator value that can safely be used in mathematical sort\n * comparisons to place things at the end of lists\n */\nconst END_OF_LIST_COMPARATOR_VALUE = 999999999999;\n\n/**\n * Returns a transit operator comparator value given a route and an optional\n * transitOperators config value. This function will do its best to handle all\n * kinds of input data as certain deployments of an implementing webapp may have\n * incomplete data and certain versions of OTP might not have a modified\n * implementation of the RouteShort model.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {mixed} this could return a string value (the route's agency name) if\n * the transitOperators value is not defined. Otherwise an integer will be\n * returned.\n */\nfunction getTransitOperatorComparatorValue(\n route: Route,\n transitOperators: TransitOperator[]\n): number | string {\n // if the transitOperators is undefined or has zero length, use the route's\n // agency name as the comparator value\n if (!transitOperators || transitOperators.length === 0) {\n // OTP Route\n if (route.agency) return route.agency.name;\n // OTP RouteShort (base OTP repo or IBI fork)\n if (route.agencyName) return route.agencyName;\n // shouldn't happen as agency names will be defined\n return \"zzz\";\n }\n\n // find operator associated with route\n const transitOperator = getTransitOperatorFromOtpRoute(\n route,\n transitOperators\n );\n\n // if transit operator not found, return infinity\n if (!transitOperator) return END_OF_LIST_COMPARATOR_VALUE;\n\n // return the transit operator's sort value or END_OF_LIST_COMPARATOR_VALUE if\n // the sort value is not a number\n return typeof transitOperator.order === \"number\"\n ? transitOperator.order\n : END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of the\n * route's agency and provided transitOperators config data.\n */\nfunction makeTransitOperatorComparator(transitOperators: TransitOperator[]) {\n return (a: Route, b: Route) => {\n const aVal = getTransitOperatorComparatorValue(a, transitOperators);\n const bVal = getTransitOperatorComparatorValue(b, transitOperators);\n if (typeof aVal === \"string\") {\n // happens when transitOperators is undefined. Both aVal are guaranteed to\n // be strings. Make a string comparison.\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n }\n // @ts-expect-error transitOperators are defined and therefore a numeric value is guaranteed\n // to be returned\n return aVal - bVal;\n };\n}\n\n/**\n * Gets the desired sort values according to an optional getter function. If the\n * getter function is not defined, the original sort values are returned.\n */\nfunction getSortValues(\n getterFn: (item: unknown) => unknown,\n a: unknown,\n b: unknown\n) {\n let aVal: unknown;\n let bVal: unknown;\n if (typeof getterFn === \"function\") {\n aVal = getterFn(a);\n bVal = getterFn(b);\n } else {\n aVal = a;\n bVal = b;\n }\n return { aVal, bVal };\n}\n\n// Lookup for the sort values associated with various OTP modes.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst modeComparatorValue = {\n SUBWAY: 1,\n TRAM: 2,\n RAIL: 3,\n GONDOLA: 4,\n FERRY: 5,\n CABLE_CAR: 6,\n FUNICULAR: 7,\n BUS: 8\n};\n\n// Lookup that maps route types to the OTP mode sort values.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst routeTypeComparatorValue = {\n 0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.\n 1: modeComparatorValue.SUBWAY, // - Subway, Metro.\n 2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.\n 3: modeComparatorValue.BUS, // - Bus.\n 4: modeComparatorValue.FERRY, // - Ferry.\n 5: modeComparatorValue.CABLE_CAR, // - Cable tram.\n 6: modeComparatorValue.GONDOLA, // - Gondola, etc.\n 7: modeComparatorValue.FUNICULAR, // - Funicular.\n // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just\n // associate them with bus/rail.\n 11: modeComparatorValue.BUS, // - Trolleybus.\n 12: modeComparatorValue.RAIL // - Monorail.\n};\n\n// Gets a comparator value for a given route's type (OTP mode).\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// ttps://github.com/documentationjs/documentation/issues/372\nfunction getRouteTypeComparatorValue(route: Route): number {\n // For some strange reason, the short route response in OTP returns the\n // string-based modes, but the long route response returns the\n // integer route type. This attempts to account for both of those cases.\n if (!route) throw new Error(`Route is undefined. ${route}`);\n if (typeof modeComparatorValue[route.mode] !== \"undefined\") {\n return modeComparatorValue[route.mode];\n }\n if (typeof routeTypeComparatorValue[route.type] !== \"undefined\") {\n return routeTypeComparatorValue[route.type];\n }\n // Default the comparator value to a large number (placing the route at the\n // end of the list).\n // eslint-disable-next-line no-console\n console.warn(\"no mode/route type found for route\", route);\n return END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of route type\n * (OTP mode).\n */\nfunction routeTypeComparator(a: Route, b: Route): number {\n return getRouteTypeComparatorValue(a) - getRouteTypeComparatorValue(b);\n}\n\n/**\n * Determines whether a value is a string that starts with an alphabetic\n * ascii character.\n */\nfunction startsWithAlphabeticCharacter(val: unknown): boolean {\n if (typeof val === \"string\" && val.length > 0) {\n const firstCharCode = val.charCodeAt(0);\n return (\n (firstCharCode >= 65 && firstCharCode <= 90) ||\n (firstCharCode >= 97 && firstCharCode <= 122)\n );\n }\n return false;\n}\n\n/**\n * Sorts routes based off of whether the shortName begins with an alphabetic\n * character. Routes with shortn that do start with an alphabetic character will\n * be prioritized over those that don't.\n */\nfunction alphabeticShortNameComparator(a: Route, b: Route): number {\n const aStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n a.shortName\n );\n const bStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n b.shortName\n );\n\n if (aStartsWithAlphabeticCharacter && bStartsWithAlphabeticCharacter) {\n // both start with an alphabetic character, return equivalence\n return 0;\n }\n // a does start with an alphabetic character, but b does not. Prioritize a\n if (aStartsWithAlphabeticCharacter) return -1;\n // b does start with an alphabetic character, but a does not. Prioritize b\n if (bStartsWithAlphabeticCharacter) return 1;\n // neither route has a shortName that starts with an alphabetic character.\n // Return equivalence\n return 0;\n}\n\n/**\n * Checks whether an appropriate comparison of numeric values can be made for\n * sorting purposes. If both values are not valid numbers according to the\n * isNaN check, then this function returns undefined which indicates that a\n * secondary sorting criteria should be used instead. If one value is valid and\n * the other is not, then the valid value will be given sorting priority. If\n * both values are valid numbers, the difference is obtained as the sort value.\n *\n * An optional argument can be provided which will be used to obtain the\n * comparison value from the comparison function arguments.\n *\n * IMPORTANT: the comparison values must be numeric values or at least be\n * attempted to be converted to numeric values! If one of the arguments is\n * something crazy like an empty string, unexpected behavior will occur because\n * JavaScript.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeNumericValueComparator(\n objGetterFn?: (item: Route) => number\n) {\n /* Note: Using the global version of isNaN (the Number version behaves differently. */\n /* eslint-disable no-restricted-globals */\n return (a: number, b: number): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n if (typeof aVal !== \"number\" || typeof bVal !== \"number\") return 0;\n\n // if both values aren't valid numbers, use the next sort criteria\n if (isNaN(aVal) && isNaN(bVal)) return 0;\n // b is a valid number, b gets priority\n if (isNaN(aVal)) return 1;\n // a is a valid number, a gets priority\n if (isNaN(bVal)) return -1;\n // a and b are valid numbers, return the sort value\n return aVal - bVal;\n };\n}\n\n/**\n * Create a comparator function that compares string values. The comparison\n * values feed to the sort comparator function are assumed to be objects that\n * will have either undefined, null or string values at the given key. If one\n * object has undefined, null or an empty string, but the other does have a\n * string with length > 0, then that string will get priority.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeStringValueComparator(\n objGetterFn?: (item: Route) => string\n) {\n return (a: string, b: string): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // both a and b are uncomparable strings, return equivalent value\n if (!aVal && !bVal) return 0;\n // a is not a comparable string, b gets priority\n if (!aVal) return 1;\n // b is not a comparable string, a gets priority\n if (!bVal) return -1;\n // a and b are comparable strings, return the sort value\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n };\n}\n\n/**\n * OpenTripPlanner sets the routeSortOrder to -999 by default. So, if that value\n * is encountered, assume that it actually means that the routeSortOrder is not\n * set in the GTFS.\n *\n * See https://github.com/opentripplanner/OpenTripPlanner/issues/2938\n * Also see https://github.com/opentripplanner/otp-react-redux/issues/122\n */\nfunction getRouteSortOrderValue(val: number): number {\n return val === -999 ? undefined : val;\n}\n\n/**\n * Create a multi-criteria sort comparator function composed of other sort\n * comparator functions. Each comparator function will be ran in the order given\n * until a non-zero comparison value is obtained which is then immediately\n * returned. If all comparison functions return equivalence, then the values\n * are assumed to be equivalent.\n */\nfunction makeMultiCriteriaSort(\n ...criteria: ((a: unknown, b: unknown) => number)[]\n) {\n return (a: number, b: number): number => {\n for (let i = 0; i < criteria.length; i++) {\n const curCriteriaComparatorValue = criteria[i](a, b);\n // if the comparison objects are not equivalent, return the value obtained\n // in this current criteria comparison\n if (curCriteriaComparatorValue !== 0) {\n return curCriteriaComparatorValue;\n }\n }\n return 0;\n };\n}\n\n/**\n * Creates a sort comparator function to compares routes for the purposes of\n * sorting and displaying in a user interface. This takes in a single optional\n * argument which should be a list of transitOperators as defined in the config\n * file. Due to GTFS feeds having varying levels of data quality, a multi-\n * criteria sort is needed to account for various differences. The criteria\n * included here are each applied to the routes in the order listed. If a given\n * sort criterion yields equivalence (e.g., two routes have the short name\n * \"20\"), the comparator falls back onto the next sort criterion (e.g., long\n * name). The sort operates on the following values (in order):\n *\n * 1. Transit Operator. The transit operator will be attempted to be obtained\n * for each route. If no argument is provided when creating this comparator\n * function, then routes will be sorted by their agency's name. If an\n * argument is provided and a match is found based off of the route's feed_id\n * and agency_id and a transitOperator's feed_id and agency_id, then the\n * field transitOperator.order will be used as the comparator value as long\n * as it is numeric. If it is not numeric, a value is returned indicating\n * that this transit operator should be placed at the end of the list.\n * 2. sortOrder. Routes that do not have a valid sortOrder will be placed\n * beneath those that do.\n * 3. route type (OTP mode). See routeTypeComparator code for prioritization of\n * route types.\n * 4. shortNames that begin with alphabetic characters. shortNames that do not\n * start with alphabetic characters will be place beneath those that do.\n * 5. shortName as integer. shortNames that cannot be parsed as integers will\n * be placed beneath those that are valid.\n * 6. shortName as string. Routes without shortNames will be placed beneath\n * those with shortNames.\n * 7. longName as string.\n */\nexport function makeRouteComparator(\n transitOperators: TransitOperator[]\n): (a: number, b: number) => number {\n return makeMultiCriteriaSort(\n makeTransitOperatorComparator(transitOperators),\n makeNumericValueComparator(obj => getRouteSortOrderValue(obj.sortOrder)),\n routeTypeComparator,\n alphabeticShortNameComparator,\n makeNumericValueComparator(obj => parseInt(obj.shortName, 10)),\n makeStringValueComparator(obj => obj.shortName),\n makeStringValueComparator(obj => obj.longName)\n );\n}\n"],"file":"route.js"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Store a javascript object at the specified key.
3
+ */
4
+ export declare function storeItem(key: string, object: unknown): void;
5
+ /**
6
+ * Retrieve a javascript object at the specified key. If not found, defaults to
7
+ * null or, the optionally provided notFoundValue.
8
+ */
9
+ export declare function getItem(key: string, notFoundValue?: unknown): unknown;
10
+ /**
11
+ * Remove item at specified key.
12
+ */
13
+ export declare function removeItem(key: string): void;
14
+ /**
15
+ * Generate a random ID. This might not quite be a UUID, but it serves our
16
+ * purposes for now.
17
+ */
18
+ export declare function randId(): string;
19
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAK5D;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,GAAE,OAAc,GAAG,OAAO,CAY3E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED;;;GAGG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAI/B"}
package/lib/storage.js CHANGED
@@ -7,6 +7,8 @@ exports.storeItem = storeItem;
7
7
  exports.getItem = getItem;
8
8
  exports.removeItem = removeItem;
9
9
  exports.randId = randId;
10
+
11
+ /* eslint-disable no-console */
10
12
  // Prefix to use with local storage keys.
11
13
  const STORAGE_PREFIX = "otp";
12
14
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/storage.js"],"names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","JSON","stringify","getItem","notFoundValue","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"mappings":";;;;;;;;;AAAA;AACA,MAAMA,cAAc,GAAG,KAAvB;AAEA;AACA;AACA;;AACO,SAASC,SAAT,CAAmBC,GAAnB,EAAwBC,MAAxB,EAAgC;AACrCC,EAAAA,MAAM,CAACC,YAAP,CAAoBC,OAApB,CACG,GAAEN,cAAe,IAAGE,GAAI,EAD3B,EAEEK,IAAI,CAACC,SAAL,CAAeL,MAAf,CAFF;AAID;AAED;AACA;AACA;AACA;;;AACO,SAASM,OAAT,CAAiBP,GAAjB,EAAsBQ,aAAa,GAAG,IAAtC,EAA4C;AACjD,MAAIC,YAAJ;;AACA,MAAI;AACFA,IAAAA,YAAY,GAAGP,MAAM,CAACC,YAAP,CAAoBI,OAApB,CAA6B,GAAET,cAAe,IAAGE,GAAI,EAArD,CAAf;AACA,UAAMU,IAAI,GAAGL,IAAI,CAACM,KAAL,CAAWF,YAAX,CAAb;AACA,QAAIC,IAAJ,EAAU,OAAOA,IAAP;AACV,WAAOF,aAAP;AACD,GALD,CAKE,OAAOI,CAAP,EAAU;AACV;AACAC,IAAAA,OAAO,CAACC,IAAR,CAAaF,CAAb,EAAgBH,YAAhB;AACA,WAAOD,aAAP;AACD;AACF;AAED;AACA;AACA;;;AACO,SAASO,UAAT,CAAoBf,GAApB,EAAyB;AAC9BE,EAAAA,MAAM,CAACC,YAAP,CAAoBY,UAApB,CAAgC,GAAEjB,cAAe,IAAGE,GAAI,EAAxD;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASgB,MAAT,GAAkB;AACvB,SAAOC,IAAI,CAACC,MAAL,GACJC,QADI,CACK,EADL,EAEJC,MAFI,CAEG,CAFH,EAEM,CAFN,CAAP;AAGD","sourcesContent":["// Prefix to use with local storage keys.\nconst STORAGE_PREFIX = \"otp\";\n\n/**\n * Store a javascript object at the specified key.\n */\nexport function storeItem(key, object) {\n window.localStorage.setItem(\n `${STORAGE_PREFIX}.${key}`,\n JSON.stringify(object)\n );\n}\n\n/**\n * Retrieve a javascript object at the specified key. If not found, defaults to\n * null or, the optionally provided notFoundValue.\n */\nexport function getItem(key, notFoundValue = null) {\n let itemAsString;\n try {\n itemAsString = window.localStorage.getItem(`${STORAGE_PREFIX}.${key}`);\n const json = JSON.parse(itemAsString);\n if (json) return json;\n return notFoundValue;\n } catch (e) {\n // Catch any errors associated with parsing bad JSON.\n console.warn(e, itemAsString);\n return notFoundValue;\n }\n}\n\n/**\n * Remove item at specified key.\n */\nexport function removeItem(key) {\n window.localStorage.removeItem(`${STORAGE_PREFIX}.${key}`);\n}\n\n/**\n * Generate a random ID. This might not quite be a UUID, but it serves our\n * purposes for now.\n */\nexport function randId() {\n return Math.random()\n .toString(36)\n .substr(2, 9);\n}\n"],"file":"storage.js"}
1
+ {"version":3,"sources":["../src/storage.ts"],"names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","JSON","stringify","getItem","notFoundValue","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"mappings":";;;;;;;;;;AAAA;AACA;AACA,MAAMA,cAAc,GAAG,KAAvB;AAEA;AACA;AACA;;AACO,SAASC,SAAT,CAAmBC,GAAnB,EAAgCC,MAAhC,EAAuD;AAC5DC,EAAAA,MAAM,CAACC,YAAP,CAAoBC,OAApB,CACG,GAAEN,cAAe,IAAGE,GAAI,EAD3B,EAEEK,IAAI,CAACC,SAAL,CAAeL,MAAf,CAFF;AAID;AAED;AACA;AACA;AACA;;;AACO,SAASM,OAAT,CAAiBP,GAAjB,EAA8BQ,aAAsB,GAAG,IAAvD,EAAsE;AAC3E,MAAIC,YAAJ;;AACA,MAAI;AACFA,IAAAA,YAAY,GAAGP,MAAM,CAACC,YAAP,CAAoBI,OAApB,CAA6B,GAAET,cAAe,IAAGE,GAAI,EAArD,CAAf;AACA,UAAMU,IAAI,GAAGL,IAAI,CAACM,KAAL,CAAWF,YAAX,CAAb;AACA,QAAIC,IAAJ,EAAU,OAAOA,IAAP;AACV,WAAOF,aAAP;AACD,GALD,CAKE,OAAOI,CAAP,EAAU;AACV;AACAC,IAAAA,OAAO,CAACC,IAAR,CAAaF,CAAb,EAAgBH,YAAhB;AACA,WAAOD,aAAP;AACD;AACF;AAED;AACA;AACA;;;AACO,SAASO,UAAT,CAAoBf,GAApB,EAAuC;AAC5CE,EAAAA,MAAM,CAACC,YAAP,CAAoBY,UAApB,CAAgC,GAAEjB,cAAe,IAAGE,GAAI,EAAxD;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASgB,MAAT,GAA0B;AAC/B,SAAOC,IAAI,CAACC,MAAL,GACJC,QADI,CACK,EADL,EAEJC,MAFI,CAEG,CAFH,EAEM,CAFN,CAAP;AAGD","sourcesContent":["/* eslint-disable no-console */\n// Prefix to use with local storage keys.\nconst STORAGE_PREFIX = \"otp\";\n\n/**\n * Store a javascript object at the specified key.\n */\nexport function storeItem(key: string, object: unknown): void {\n window.localStorage.setItem(\n `${STORAGE_PREFIX}.${key}`,\n JSON.stringify(object)\n );\n}\n\n/**\n * Retrieve a javascript object at the specified key. If not found, defaults to\n * null or, the optionally provided notFoundValue.\n */\nexport function getItem(key: string, notFoundValue: unknown = null): unknown {\n let itemAsString: string;\n try {\n itemAsString = window.localStorage.getItem(`${STORAGE_PREFIX}.${key}`);\n const json = JSON.parse(itemAsString);\n if (json) return json;\n return notFoundValue;\n } catch (e) {\n // Catch any errors associated with parsing bad JSON.\n console.warn(e, itemAsString);\n return notFoundValue;\n }\n}\n\n/**\n * Remove item at specified key.\n */\nexport function removeItem(key: string): void {\n window.localStorage.removeItem(`${STORAGE_PREFIX}.${key}`);\n}\n\n/**\n * Generate a random ID. This might not quite be a UUID, but it serves our\n * purposes for now.\n */\nexport function randId(): string {\n return Math.random()\n .toString(36)\n .substr(2, 9);\n}\n"],"file":"storage.js"}
package/lib/time.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { Config } from "@opentripplanner/types";
2
+ import { formatTime, formatDurationWithSeconds, formatDuration } from "./deprecated-with-types";
3
+ export { formatTime, formatDuration, formatDurationWithSeconds };
4
+ export declare const OTP_API_DATE_FORMAT = "YYYY-MM-DD";
5
+ export declare const OTP_API_DATE_FORMAT_DATE_FNS = "yyyy-MM-dd";
6
+ export declare const OTP_API_TIME_FORMAT = "HH:mm";
7
+ /**
8
+ * To ease the transition away from moment.js, this method uses date-fns to format durations
9
+ * the way moment.js did.
10
+ * @param {number} seconds The number of seconds to format
11
+ * @param {boolean} showSeconds Whether to render seconds or not
12
+ * @param {boolean} localize If true, will create output like moment.js using date-fns locale.
13
+ * Otherwise, uses date-fns default
14
+ * @returns Formatted duration
15
+ */
16
+ export declare function formatDurationLikeMoment(seconds: number, showSeconds: boolean, localize?: {
17
+ enabled: boolean;
18
+ code: string;
19
+ }): string;
20
+ /**
21
+ * Breaks up a duration in seconds into hours, minutes, and seconds.
22
+ * @param {number} seconds The number of seconds to break up
23
+ * @returns an object with fields with the corresponding, hours, minutes, seconds.
24
+ */
25
+ export declare function toHoursMinutesSeconds(seconds: any): {
26
+ hours: number;
27
+ minutes: number;
28
+ seconds: number;
29
+ };
30
+ /**
31
+ * @param {[type]} config the OTP config object found in store
32
+ * @return {string} the config-defined time formatter or HH:mm (24-hr time)
33
+ */
34
+ export declare function getTimeFormat(config: Config): string;
35
+ export declare function getDateFormat(config: Config): string;
36
+ export declare function getLongDateFormat(config: Config): string;
37
+ /**
38
+ * Offsets a time according to the provided time options
39
+ * and returns the result.
40
+ */
41
+ export declare function offsetTime(ms: any, options: any): any;
42
+ /**
43
+ * Formats a seconds after midnight value for display in narrative
44
+ * @param {number} seconds time since midnight in seconds
45
+ * @param {string} timeFormat A valid date-fns time format
46
+ * @return {string} formatted text representation
47
+ */
48
+ export declare function formatSecondsAfterMidnight(seconds: number, timeFormat: string): string;
49
+ /**
50
+ * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test
51
+ * environment, pulls timezone information from an env variable. Default to
52
+ * GMT+0 if the Intl API is unavailable.
53
+ */
54
+ export declare function getUserTimezone(fallbackTimezone?: string): string;
55
+ /**
56
+ * Formats current time for use in OTP query
57
+ * The conversion to the user's timezone is needed for testing purposes.
58
+ */
59
+ export declare function getCurrentTime(timezone?: string): string;
60
+ /**
61
+ * Formats current date for use in OTP query
62
+ * The conversion to the user's timezone is needed for testing purposes.
63
+ */
64
+ export declare function getCurrentDate(timezone?: string): string;
65
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.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@ -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,IAAgBD,OAAO,GAAG,EAA3B,IAAkCA,OAAO,KAAK,CAAlD,EAAqD;AACnD,WAAO,OAAP;AACD;;AAED,QAAMK,KAAK,GAAGC,IAAI,CAACC,KAAL,CAAWP,OAAO,GAAG,IAArB,CAAd;AACA,QAAMQ,OAAO,GAAGF,IAAI,CAACC,KAAL,CAAW,CAACP,OAAO,GAAGK,KAAK,GAAG,IAAnB,IAA2B,EAAtC,CAAhB;AACA,QAAMI,eAAe,GAAGR,WAAW,GAC/BD,OAAO,GAAGK,KAAK,GAAG,IAAlB,GAAyBG,OAAO,GAAG,EADJ,GAE/B,CAFJ;AAGA,QAAME,UAAU,GAAG;AACjBC,IAAAA,MAAM,EAAE,IADS;AAEjBC,IAAAA,QAAQ,EAAE,KAFO;AAGjBC,IAAAA,QAAQ,EAAE;AAHO,GAAnB;AAKA,QAAMC,MAAM,GAAGZ,QAAQ,GACnB;AACE;AACAE,IAAAA,IAAI,EAAE,CAAAF,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAEE,IAAV,KAAkB,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,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,EAAsD;AAC3D,SAAO,qBAAO,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CAAP,EAA6CrD,mBAA7C,CAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASuD,cAAT,CAAwBF,QAAQ,GAAGX,eAAe,EAAlD,EAAsD;AAC3D,SAAO,qBACL,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CADK,EAELtD,4BAFK,CAAP;AAID","sourcesContent":["import {\n startOfDay,\n add,\n format,\n formatDuration as dateFnsFormatDuration\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,GAAG,EAA3B,IAAkCA,OAAO,KAAK,CAAlD,EAAqD;AACnD,WAAO,OAAP;AACD;;AAED,QAAMK,KAAK,GAAGC,IAAI,CAACC,KAAL,CAAWP,OAAO,GAAG,IAArB,CAAd;AACA,QAAMQ,OAAO,GAAGF,IAAI,CAACC,KAAL,CAAW,CAACP,OAAO,GAAGK,KAAK,GAAG,IAAnB,IAA2B,EAAtC,CAAhB;AACA,QAAMI,eAAe,GAAGR,WAAW,GAC/BD,OAAO,GAAGK,KAAK,GAAG,IAAlB,GAAyBG,OAAO,GAAG,EADJ,GAE/B,CAFJ;AAGA,QAAME,UAAU,GAAG;AACjBC,IAAAA,MAAM,EAAE,IADS;AAEjBC,IAAAA,QAAQ,EAAE,KAFO;AAGjBC,IAAAA,QAAQ,EAAE;AAHO,GAAnB;AAKA,QAAMC,MAAM,GAAGZ,QAAQ,GACnB;AACE;AACAE,IAAAA,IAAI,EAAE,CAAAF,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAEE,IAAV,KAAkB,OAF1B;AAGEW,I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,QAAR,wEAAkBK,cAAlB,KAAoC,aAA3C;AACD;AACD;AACA;AACA;AACA;;;AACO,SAASC,UAAT,CAAoBC,EAApB,EAAwBC,OAAxB,EAAiC;AACtC,SAAOD,EAAE,IAAI,CAAAC,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEC,MAAT,KAAmB,CAAvB,CAAT;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,0BAAT,CACLjC,OADK,EAELwB,UAFK,EAGG;AACR,QAAMU,IAAI,GAAG,kBAAI,yBAAW,IAAIC,IAAJ,EAAX,CAAJ,EAA4B;AAAEnC,IAAAA;AAAF,GAA5B,CAAb;AACA,SAAO,qBAAOkC,IAAP,EAAaV,UAAb,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASY,eAAT,CAAyBC,gBAAgB,GAAG,eAA5C,EAAqE;AAAA;;AAC1E,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,S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,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.4",
3
+ "version": "5.0.0",
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
  }
@@ -69,7 +69,6 @@ Object {
69
69
  "maxWalkDistance": 1609,
70
70
  "mode": "WALK,FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT,TRANSIT",
71
71
  "numItineraries": 3,
72
- "optimize": "QUICK",
73
72
  "otherThanPreferredRoutesPenalty": 900,
74
73
  "showIntermediateStops": true,
75
74
  "time": "21:53",
@@ -103,7 +102,6 @@ Object {
103
102
  "maxWalkDistance": 1609,
104
103
  "mode": "FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT,WALK,BIKE,WALK,TRANSIT,BUS",
105
104
  "numItineraries": 3,
106
- "optimize": "QUICK",
107
105
  "otherThanPreferredRoutesPenalty": 900,
108
106
  "showIntermediateStops": true,
109
107
  "time": "21:53",
@@ -123,7 +121,6 @@ Object {
123
121
  "mode": "CAR_RENT,BUS,WALK",
124
122
  "numItineraries": 3,
125
123
  "onlyTransitTrips": true,
126
- "optimize": "QUICK",
127
124
  "otherThanPreferredRoutesPenalty": 900,
128
125
  "searchTimeout": 10000,
129
126
  "showIntermediateStops": true,
@@ -160,7 +157,6 @@ Object {
160
157
  "maxWalkDistance": 1609,
161
158
  "mode": "WALK,TRANSIT",
162
159
  "numItineraries": 3,
163
- "optimize": "QUICK",
164
160
  "otherThanPreferredRoutesPenalty": 900,
165
161
  "showIntermediateStops": true,
166
162
  "time": "21:53",
@@ -181,7 +177,6 @@ Object {
181
177
  "maximumMicromobilitySpeed": 5,
182
178
  "mode": "MICROMOBILITY,BUS",
183
179
  "numItineraries": 3,
184
- "optimize": "QUICK",
185
180
  "otherThanPreferredRoutesPenalty": 900,
186
181
  "showIntermediateStops": true,
187
182
  "time": "21:53",
@@ -202,7 +197,6 @@ Object {
202
197
  "maxWalkDistance": 4828,
203
198
  "mode": "SCOOTER,BUS",
204
199
  "numItineraries": 3,
205
- "optimize": "QUICK",
206
200
  "otherThanPreferredRoutesPenalty": 900,
207
201
  "showIntermediateStops": true,
208
202
  "time": "21:53",
@@ -219,7 +213,6 @@ Object {
219
213
  "maxWalkDistance": 1609,
220
214
  "mode": "WALK,TRANSIT,FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT",
221
215
  "numItineraries": 3,
222
- "optimize": "QUICK",
223
216
  "otherThanPreferredRoutesPenalty": 900,
224
217
  "showIntermediateStops": true,
225
218
  "time": "21:53",
@@ -252,7 +245,6 @@ Object {
252
245
  "maxWalkDistance": 1609,
253
246
  "mode": "WALK,TRANSIT",
254
247
  "numItineraries": 3,
255
- "optimize": "QUICK",
256
248
  "otherThanPreferredRoutesPenalty": 900,
257
249
  "showIntermediateStops": true,
258
250
  "time": "21:53",
@@ -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",