@opentripplanner/core-utils 7.0.0-alpha.3 → 7.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.
package/lib/query.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/query.js"],"names":["defaultParams","TIME_FORMATS","OTP_API_TIME_FORMAT","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","length","firstAccess","find","push","getUrlParams","qs","parse","window","location","href","split","getOtpUrlParams","Object","keys","key","startsWith","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","from","to","getDefaultQueryParamValue","param","default","getDefaultQuery","config","defaultQuery","routingType","queryParams","qp","forEach","name","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","reduce","prev","cur","newModes","expandOtpFlexMode","mode","map","join","isNotDefaultQuery","activeModes","sort","defaultModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoder","search","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","lat","lon","queryParamToLocation","planParamsToQuery","params","fromPlace","toPlace","arriveBy","matchedTimeFormat","timeFormat","Date","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","indexOf","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","OTP_API_DATE_FORMAT_DATE_FNS","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","reducedMode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAOA;AAEA;;AAEA;AAEO,MAAMA,aAAa,GAAG,CAC3B,YAD2B,EAE3B,iBAF2B,EAG3B,gBAH2B,EAI3B,aAJ2B,EAK3B,WAL2B,EAM3B,iBAN2B,EAO3B,aAP2B,EAQ3B,WAR2B,EAS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H,yBAA1B,CAAvB;AACA,UAAMoH,YAAY,GAAG,sBAAQ7B,MAAM,CAAC8B,OAAf,EAAwBrH,yBAAxB,CAArB;;AAEA,QAAI,CAACkH,cAAD,IAAmB,CAACE,YAAxB,EAAsC;AACpC,aAAO7B,MAAM,CAAC2B,cAAd;AACA,aAAO3B,MAAM,CAAC6B,YAAd;AACD;AACF,GA1E2E,CA4E5E;AAEA;;;AACA,MAAI,uBAAO7B,MAAM,CAAC9B,IAAd,CAAJ,EAAyB;AACvB8B,IAAAA,MAAM,CAAC9B,IAAP,IAAe,OAAf;AACD,GAjF2E,CAmF5E;;;AACA,MAAI8B,MAAM,CAAC9B,IAAX,EAAiB;AACf;AACA,UAAM6D,WAAW,GAAGpE,kBAAkB,CAACqC,MAAM,CAAC9B,IAAP,CAAYrC,KAAZ,CAAkB,GAAlB,CAAD,CAAlB,CAA2CuC,IAA3C,CAAgD,GAAhD,CAApB;AACA4B,IAAAA,MAAM,CAAC9B,IAAP,GAAcD,iBAAiB,CAAC8D,WAAD,CAA/B;AACD;;AAED,SAAO/B,MAAP;AACD","sourcesContent":["import { format, isMatch, parse } from \"date-fns\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport { getTransitModes, hasCar, isAccessMode } from \"./itinerary\";\nimport { coordsToString, stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_TIME_FORMAT,\n OTP_API_DATE_FORMAT_DATE_FNS\n} from \"./time\";\n\n// import { coordsToString, summarizeQuery } from \"./deprecated\";\n\n// export { summarizeQuery };\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"walkReluctance\",\n \"maxWalkTime\",\n \"walkSpeed\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\",\n OTP_API_TIME_FORMAT // 'HH:mm'\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n return qs.parse(window.location.href.split(\"?\")[1]);\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes) {\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the exapnded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(query.mode.split(\",\").sort());\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @return {Location}\n */\nasync function getFirstGeocodeResult(text, geocoderConfig) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder.search({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(value, geocoderConfig);\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n // Match one of the supported time formats\n const matchedTimeFormat = TIME_FORMATS.find(timeFormat =>\n isMatch(params.time, timeFormat)\n );\n query.time = matchedTimeFormat\n ? format(\n parse(params.time, matchedTimeFormat, new Date()),\n OTP_API_TIME_FORMAT\n )\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = isMatch(params.date, OTP_API_DATE_FORMAT_DATE_FNS);\n const timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = isMatch(params.startTime, OTP_API_TIME_FORMAT);\n const endTimeValid = isMatch(params.endTime, OTP_API_TIME_FORMAT);\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n if (params.mode) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"file":"query.js"}
1
+ {"version":3,"sources":["../src/query.js"],"names":["defaultParams","TIME_FORMATS","OTP_API_TIME_FORMAT","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","length","firstAccess","find","push","getUrlParams","qs","parse","window","location","href","split","getOtpUrlParams","Object","keys","key","startsWith","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","from","to","getDefaultQueryParamValue","param","default","getDefaultQuery","config","defaultQuery","routingType","queryParams","qp","forEach","name","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","enabled","reduce","prev","cur","newModes","expandOtpFlexMode","mode","map","join","isNotDefaultQuery","activeModes","sort","mergeFlex","defaultModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoder","search","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","lat","lon","queryParamToLocation","planParamsToQuery","params","fromPlace","toPlace","arriveBy","matchedTimeFormat","timeFormat","Date","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","indexOf","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","OTP_API_DATE_FORMAT","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","reducedMode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAOA;AAEO,MAAMA,aAAa,GAAG,CAC3B,YAD2B,EAE3B,iBAF2B,EAG3B,gBAH2B,EAI3B,aAJ2B,EAK3B,WAL2B,EAM3B,iBAN2B,EAO3B,aAP2B,EAQ3B,WAR2B,EAS3B,UAT2B,EAU3B,cAV2B,EAW3B,qBAX2B,EAY3B,OAZ2B,CAAtB;AAeP;AACA;AACA;;;AACA,MAAMC,YAAY,GAAG,CACnB,UADmB,EAEnB,WAFmB,EAGnB,UAHmB,EAInB,QAJmB,EAKnB,OALmB,EAMnB,MANmB,EAOnB,MAPmB,EAQnB,KARmB,EASnB,IATmB,EAUnBC,yBAVmB,CAUC;AAVD,CAArB;AAaA;AACA;;AAEO,SAASC,qBAAT,CAA+BC,SAA/B,EAA0CC,QAA1C,EAAoDC,KAApD,EAA2D;AAChE,SAAO,OAAOF,SAAS,CAACC,QAAD,CAAhB,KAA+B,UAA/B,GACHD,SAAS,CAACC,QAAD,CAAT,CAAoBC,KAApB,CADG,GAEHF,SAAS,CAACC,QAAD,CAFb;AAGD;;AAEM,SAASE,sBAAT,CAAgCC,UAAhC,EAA4C;AACjD;AACA,QAAMC,WAAW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AAP,IAAe,mBAAApB,MAAM,CAACa,KAAP,kEAAca,SAAd,MAA4B,KAA/C,EAAsD;AACpD;AACA,UAAMwD,WAAW,GAAGtE,kBAAkB,CAACuC,MAAM,CAAC/B,IAAP,CAAYtC,KAAZ,CAAkB,GAAlB,CAAD,CAAlB,CAA2CwC,IAA3C,CAAgD,GAAhD,CAApB;AACA6B,IAAAA,MAAM,CAAC/B,IAAP,GAAcD,iBAAiB,CAAC+D,WAAD,CAA/B;AACD;;AAED,SAAO/B,MAAP;AACD","sourcesContent":["import { format, isMatch, parse } from \"date-fns\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport { getTransitModes, hasCar, isAccessMode } from \"./itinerary\";\nimport { coordsToString, stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_DATE_FORMAT,\n OTP_API_TIME_FORMAT\n} from \"./time\";\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"walkReluctance\",\n \"maxWalkTime\",\n \"walkSpeed\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\",\n OTP_API_TIME_FORMAT // 'HH:mm'\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n return qs.parse(window.location.href.split(\"?\")[1]);\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes, enabled = true) {\n if (!enabled) return modes;\n\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the exapnded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(\n query.mode.split(\",\").sort(),\n config.modes?.mergeFlex\n );\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @return {Location}\n */\nasync function getFirstGeocodeResult(text, geocoderConfig) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder.search({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(value, geocoderConfig);\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n // Match one of the supported time formats\n const matchedTimeFormat = TIME_FORMATS.find(timeFormat =>\n isMatch(params.time, timeFormat)\n );\n query.time = matchedTimeFormat\n ? format(\n parse(params.time, matchedTimeFormat, new Date()),\n OTP_API_TIME_FORMAT\n )\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = isMatch(params.date, OTP_API_DATE_FORMAT);\n const timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = isMatch(params.startTime, OTP_API_TIME_FORMAT);\n const endTimeValid = isMatch(params.endTime, OTP_API_TIME_FORMAT);\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n // Explicit false check allows avoiding a breaking change -- undefined is true\n if (params.mode && config.modes?.mergeFlex !== false) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"file":"query.js"}
package/lib/time.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Config } from "@opentripplanner/types";
2
- export declare const OTP_API_DATE_FORMAT = "YYYY-MM-DD";
3
- export declare const OTP_API_DATE_FORMAT_DATE_FNS = "yyyy-MM-dd";
2
+ export declare const OTP_API_DATE_FORMAT = "yyyy-MM-dd";
4
3
  export declare const OTP_API_TIME_FORMAT = "HH:mm";
5
4
  /**
6
5
  * Breaks up a duration in seconds into hours, minutes, and seconds.
package/lib/time.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAMhD,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAGhD,eAAO,MAAM,4BAA4B,eAAe,CAAC;AACzD,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GACd;IACD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CA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AE,OAAO,KAAA,OAErC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CAGR;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,gBAAgB,SAAkB,GAAG,MAAM,CAG1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAoB,GAAG,MAAM,CAEnE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAoB,GAAG,MAAM,CAEnE"}
package/lib/time.js CHANGED
@@ -12,20 +12,16 @@ exports.formatSecondsAfterMidnight = formatSecondsAfterMidnight;
12
12
  exports.getUserTimezone = getUserTimezone;
13
13
  exports.getCurrentTime = getCurrentTime;
14
14
  exports.getCurrentDate = getCurrentDate;
15
- exports.OTP_API_TIME_FORMAT = exports.OTP_API_DATE_FORMAT_DATE_FNS = exports.OTP_API_DATE_FORMAT = void 0;
15
+ exports.OTP_API_TIME_FORMAT = exports.OTP_API_DATE_FORMAT = void 0;
16
16
 
17
17
  var _dateFns = require("date-fns");
18
18
 
19
19
  var _dateFnsTz = require("date-fns-tz");
20
20
 
21
- // special constants for making sure the following date format is always sent to
22
- // OTP regardless of whatever the user has configured as the display format
23
- const OTP_API_DATE_FORMAT = "YYYY-MM-DD"; // Date-Fns uses a different string format than moment.js
24
- // see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
25
-
21
+ // Date/time formats (per date-fns) when sending/receiving date from OTP
22
+ // regardless of whatever the user has configured as the display format.
23
+ const OTP_API_DATE_FORMAT = "yyyy-MM-dd";
26
24
  exports.OTP_API_DATE_FORMAT = OTP_API_DATE_FORMAT;
27
- const OTP_API_DATE_FORMAT_DATE_FNS = "yyyy-MM-dd";
28
- exports.OTP_API_DATE_FORMAT_DATE_FNS = OTP_API_DATE_FORMAT_DATE_FNS;
29
25
  const OTP_API_TIME_FORMAT = "HH:mm";
30
26
  /**
31
27
  * Breaks up a duration in seconds into hours, minutes, and seconds.
@@ -117,6 +113,6 @@ function getCurrentTime(timezone = getUserTimezone()) {
117
113
 
118
114
 
119
115
  function getCurrentDate(timezone = getUserTimezone()) {
120
- return (0, _dateFns.format)((0, _dateFnsTz.utcToZonedTime)(Date.now(), timezone), OTP_API_DATE_FORMAT_DATE_FNS);
116
+ return (0, _dateFns.format)((0, _dateFnsTz.utcToZonedTime)(Date.now(), timezone), OTP_API_DATE_FORMAT);
121
117
  }
122
118
  //# sourceMappingURL=time.js.map
package/lib/time.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/time.ts"],"names":["OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","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;;AACA;;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;;;;AACO,SAASC,qBAAT,CACLC,OADK,EAML;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEC,IAAI,CAACC,KAAL,CAAWH,OAAO,GAAG,IAArB,CADF;AAELI,IAAAA,OAAO,EAAEF,IAAI,CAACC,KAAL,CAAWH,OAAO,GAAG,EAArB,IAA2B,EAF/B;AAGLA,IAAAA,OAAO,EAAEA,OAAO,GAAG;AAHd,GAAP;AAKD;AAED;AACA;AACA;AACA;;;AACO,SAASK,aAAT,CAAuBC,MAAvB,EAA+C;AAAA;;AACpD,SAAO,CAAAA,MA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D;AACnE,SAAO,qBAAO,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CAAP,EAA6CjC,mBAA7C,CAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASmC,cAAT,CAAwBF,QAAQ,GAAGX,eAAe,EAAlD,EAA8D;AACnE,SAAO,qBACL,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CADK,EAELlC,4BAFK,CAAP;AAID","sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport { startOfDay, add, format } 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 * 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(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 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"}
1
+ {"version":3,"sources":["../src/time.ts"],"names":["OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","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;;AACA;;AAEA;AACA;AACO,MAAMA,mBAAmB,GAAG,YAA5B;;AACA,MAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;;;;AACO,SAASC,qBAAT,CACLC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yBC,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,EAA6CjC,mBAA7C,CAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASmC,cAAT,CAAwBF,QAAQ,GAAGX,eAAe,EAAlD,EAA8D;AACnE,SAAO,qBAAO,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CAAP,EAA6ClC,mBAA7C,CAAP;AACD","sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport { startOfDay, add, format } from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// Date/time formats (per date-fns) when sending/receiving date from OTP\n// regardless of whatever the user has configured as the display format.\nexport const OTP_API_DATE_FORMAT = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\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(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 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(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);\n}\n"],"file":"time.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentripplanner/core-utils",
3
- "version": "7.0.0-alpha.3",
3
+ "version": "7.0.1",
4
4
  "description": "Core functionality that is shared among numerous UI components",
5
5
  "engines": {
6
6
  "node": ">=13"
@@ -13,7 +13,7 @@
13
13
  "private": false,
14
14
  "dependencies": {
15
15
  "@mapbox/polyline": "^1.1.0",
16
- "@opentripplanner/geocoder": "^1.2.2",
16
+ "@opentripplanner/geocoder": "^1.3.0",
17
17
  "@styled-icons/foundation": "^10.34.0",
18
18
  "@turf/along": "^6.0.1",
19
19
  "bowser": "^2.7.0",
@@ -28,6 +28,6 @@
28
28
  "tsc": "tsc"
29
29
  },
30
30
  "devDependencies": {
31
- "@opentripplanner/types": "3.0.0-alpha.4"
31
+ "@opentripplanner/types": "^3.0.0"
32
32
  }
33
33
  }
@@ -7,47 +7,57 @@ import {
7
7
 
8
8
  const bikeRentalItinerary = require("./__mocks__/bike-rental-itinerary.json");
9
9
  const tncItinerary = require("./__mocks__/tnc-itinerary.json");
10
- // const multiCurrencyItinerary = require("./__mocks__/multi-currency-itinerary.json");
11
10
 
12
11
  describe("util > itinerary", () => {
13
- it("isTransit should work", () => {
14
- expect(isTransit("CAR")).toBeFalsy();
12
+ describe("isTransit", () => {
13
+ it("should work", () => {
14
+ expect(isTransit("CAR")).toBeFalsy();
15
+ expect(isTransit("BUS")).toBeTruthy();
16
+ });
15
17
  });
16
18
 
17
- it("getCompanyFromLeg should return company for bike rental leg", () => {
18
- const company = getCompanyFromLeg(bikeRentalItinerary.legs[1]);
19
- expect(company).toEqual("GBFS");
20
- });
19
+ describe("getCompanyFromLeg", () => {
20
+ it("should return company for bike rental leg", () => {
21
+ const company = getCompanyFromLeg(bikeRentalItinerary.legs[1]);
22
+ expect(company).toEqual("GBFS");
23
+ });
21
24
 
22
- it("getCompanyFromLeg should return company for TNC leg", () => {
23
- const company = getCompanyFromLeg(tncItinerary.legs[0]);
24
- expect(company).toEqual("UBER");
25
+ it("should return company for TNC leg", () => {
26
+ const company = getCompanyFromLeg(tncItinerary.legs[0]);
27
+ expect(company).toEqual("UBER");
28
+ });
25
29
  });
26
30
 
27
- it("getTransitFare should return defaults with missing fare", () => {
28
- const { transitFare } = getTransitFare(null);
29
- // transit fare value should be zero
30
- expect(transitFare).toMatchSnapshot();
31
- });
31
+ describe("getTransitFare", () => {
32
+ it("should return defaults with missing fare", () => {
33
+ const { transitFare } = getTransitFare(null);
34
+ // transit fare value should be zero
35
+ expect(transitFare).toMatchSnapshot();
36
+ });
32
37
 
33
- it("getTransitFare should work with valid fare component", () => {
34
- const fareComponent = {
35
- currency: {
36
- currency: "USD",
37
- defaultFractionDigits: 2,
38
- currencyCode: "USD",
39
- symbol: "$"
40
- },
41
- cents: 575
42
- };
43
- const { currencyCode, transitFare } = getTransitFare(fareComponent);
44
- expect(currencyCode).toEqual(fareComponent.currency.currencyCode);
45
- // Snapshot tests
46
- expect(transitFare).toMatchSnapshot();
38
+ it("should work with valid fare component", () => {
39
+ const fareComponent = {
40
+ currency: {
41
+ currency: "USD",
42
+ defaultFractionDigits: 2,
43
+ currencyCode: "USD",
44
+ symbol: "$"
45
+ },
46
+ cents: 575
47
+ };
48
+ const { currencyCode, transitFare } = getTransitFare(fareComponent);
49
+ expect(currencyCode).toEqual(fareComponent.currency.currencyCode);
50
+ // Snapshot tests
51
+ expect(transitFare).toMatchSnapshot();
52
+ });
47
53
  });
48
54
 
49
- it("calculateFare should return the correct currency code for TNC leg", () => {
50
- const fareResult = calculateTncFares(tncItinerary, true);
51
- expect(fareResult.currencyCode).toEqual("USD");
55
+ describe("calculateTncFares", () => {
56
+ it("should return the correct amounts and currency for an itinerary with TNC", () => {
57
+ const fareResult = calculateTncFares(tncItinerary, true);
58
+ expect(fareResult.currencyCode).toEqual("USD");
59
+ expect(fareResult.maxTNCFare).toEqual(19);
60
+ expect(fareResult.minTNCFare).toEqual(17);
61
+ });
52
62
  });
53
63
  });
package/src/itinerary.ts CHANGED
@@ -13,32 +13,6 @@ import {
13
13
  } from "@opentripplanner/types";
14
14
  import turfAlong from "@turf/along";
15
15
 
16
- /*
17
- import {
18
- // calculateFares,
19
- // getLegModeLabel,
20
- // getModeForPlace,
21
- // getPlaceName,
22
- // getStepDirection,
23
- // getStepInstructions,
24
- // getStepStreetName,
25
- // getTimeZoneOffset,
26
- // getTransitFare
27
- } from "./deprecated";
28
-
29
- export {
30
- // calculateFares,
31
- // getLegModeLabel,
32
- // getModeForPlace,
33
- // getPlaceName,
34
- // getStepDirection,
35
- // getStepInstructions,
36
- // getStepStreetName,
37
- // getTimeZoneOffset,
38
- // getTransitFare
39
- };
40
- */
41
-
42
16
  // All OTP transit modes
43
17
  export const transitModes = [
44
18
  "TRAM",
@@ -455,24 +429,24 @@ export function calculatePhysicalActivity(
455
429
  * It is assumed that the same currency is used for all TNC legs.
456
430
  */
457
431
  export function calculateTncFares(itinerary: Itinerary): TncFare {
458
- let minTNCFare = 0;
459
- let maxTNCFare = 0;
460
- let currencyCode;
461
- itinerary.legs.forEach(({ hailedCar, mode, tncData }) => {
462
- if (mode === "CAR" && hailedCar && tncData) {
463
- const { currency, maxCost, minCost } = tncData;
464
- minTNCFare += minCost;
465
- maxTNCFare += maxCost;
466
- // Assumes a single currency for entire itinerary.
467
- currencyCode = currency;
468
- }
469
- });
470
-
471
- return {
472
- currencyCode,
473
- maxTNCFare,
474
- minTNCFare
475
- };
432
+ return itinerary.legs
433
+ .filter(leg => leg.mode === "CAR" && leg.hailedCar && leg.tncData)
434
+ .reduce(
435
+ ({ maxTNCFare, minTNCFare }, { tncData }) => {
436
+ const { currency, maxCost, minCost } = tncData;
437
+ return {
438
+ // Assumes a single currency for entire itinerary.
439
+ currencyCode: currency,
440
+ maxTNCFare: maxTNCFare + maxCost,
441
+ minTNCFare: minTNCFare + minCost
442
+ };
443
+ },
444
+ {
445
+ currencyCode: null,
446
+ maxTNCFare: 0,
447
+ minTNCFare: 0
448
+ }
449
+ );
476
450
  }
477
451
 
478
452
  /**
@@ -485,17 +459,77 @@ export function getTransitFare(
485
459
  currencyCode: string;
486
460
  transitFare: number;
487
461
  } {
488
- // Default values (if fare component is not valid).
489
- let transitFare = 0;
490
- let currencyCode = "USD";
491
- if (fareComponent) {
492
- // Assign values without declaration.
493
- // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration
494
- ({ currencyCode } = fareComponent.currency);
495
- transitFare = fareComponent.cents;
496
- }
497
- return {
498
- currencyCode,
499
- transitFare
462
+ return fareComponent
463
+ ? {
464
+ currencyCode: fareComponent.currency.currencyCode,
465
+ transitFare: fareComponent.cents
466
+ }
467
+ : {
468
+ currencyCode: "USD",
469
+ transitFare: 0
470
+ };
471
+ }
472
+
473
+ /**
474
+ * Sources:
475
+ * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf
476
+ * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey
477
+ * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx
478
+ * Other values extrapolated.
479
+ */
480
+ const CARBON_INTENSITY_DEFAULTS = {
481
+ walk: 0.026,
482
+ bicycle: 0.017,
483
+ car: 0.162,
484
+ tram: 0.066,
485
+ subway: 0.066,
486
+ rail: 0.066,
487
+ bus: 0.09,
488
+ ferry: 0.082,
489
+ cable_car: 0.021,
490
+ gondola: 0.021,
491
+ funicular: 0.066,
492
+ transit: 0.066,
493
+ leg_switch: 0,
494
+ airplane: 0.382,
495
+ micromobility: 0.095
496
+ };
497
+
498
+ /**
499
+ * @param {itinerary} itinerary OTP trip itinierary
500
+ * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
501
+ * @param {units} units units to be used in return value
502
+ * @return Amount of carbon in chosen unit
503
+ */
504
+ export function calculateEmissions(
505
+ itinerary: Itinerary,
506
+ carbonIntensity: Record<string, number> = {},
507
+ units?: string
508
+ ): number {
509
+ // Apply defaults for any values that we don't have.
510
+ const carbonIntensityWithDefaults = {
511
+ ...CARBON_INTENSITY_DEFAULTS,
512
+ ...carbonIntensity
500
513
  };
514
+
515
+ // Distance is in meters, totalCarbon is in grams
516
+ const totalCarbon =
517
+ itinerary?.legs?.reduce((total, leg) => {
518
+ return (
519
+ (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||
520
+ 0) + total
521
+ );
522
+ }, 0) || 0;
523
+
524
+ switch (units) {
525
+ case "ounce":
526
+ return totalCarbon / 28.35;
527
+ case "kilogram":
528
+ return totalCarbon / 1000;
529
+ case "pound":
530
+ return totalCarbon / 454;
531
+ case "gram":
532
+ default:
533
+ return totalCarbon;
534
+ }
501
535
  }
package/src/map.ts CHANGED
@@ -1,16 +1,4 @@
1
1
  import { LatLngArray, Location, UserPosition } from "@opentripplanner/types";
2
- import { toSentenceCase } from "./itinerary";
3
-
4
- /*
5
- import {
6
- // coordsToString,
7
- // getDetailText //,
8
- // latlngToString,
9
- // logDeprecationWarning
10
- } from "./deprecated";
11
-
12
- export { coordsToString, getDetailText , latlngToString };
13
- */
14
2
 
15
3
  export function currentPositionToLocation(
16
4
  currentPosition: UserPosition
@@ -28,8 +16,8 @@ export function currentPositionToLocation(
28
16
  };
29
17
  }
30
18
 
31
- // TRICKY: It is used in query.js and in the context of
32
- // otp-rr actions where the intl context is not available.
19
+ // TRICKY: This method is used in query.js and in the context of
20
+ // otp-rr actions where the intl context is not available/does not apply.
33
21
  export function coordsToString(coords: number[]): string {
34
22
  return coords.length && coords.map(c => (+c).toFixed(5)).join(", ");
35
23
  }
@@ -48,12 +36,6 @@ export function constructLocation(latlng: {
48
36
  };
49
37
  }
50
38
 
51
- export function formatStoredPlaceName(location: Location): string {
52
- return location.type === "home" || location.type === "work"
53
- ? toSentenceCase(location.type)
54
- : location.name;
55
- }
56
-
57
39
  export function matchLatLon(location1: Location, location2: Location): boolean {
58
40
  if (!location1 || !location2) return location1 === location2;
59
41
  return location1.lat === location2.lat && location1.lon === location2.lon;
package/src/query.js CHANGED
@@ -8,14 +8,10 @@ import queryParams from "./query-params";
8
8
  import {
9
9
  getCurrentTime,
10
10
  getCurrentDate,
11
- OTP_API_TIME_FORMAT,
12
- OTP_API_DATE_FORMAT_DATE_FNS
11
+ OTP_API_DATE_FORMAT,
12
+ OTP_API_TIME_FORMAT
13
13
  } from "./time";
14
14
 
15
- // import { coordsToString, summarizeQuery } from "./deprecated";
16
-
17
- // export { summarizeQuery };
18
-
19
15
  /* The list of default parameters considered in the settings panel */
20
16
 
21
17
  export const defaultParams = [
@@ -148,7 +144,9 @@ function isParamApplicable(paramInfo, query, config) {
148
144
  * Helper method which replaces OTP flex modes with single FLEX mode that's
149
145
  * more useful and easier to work with.
150
146
  */
151
- export function reduceOtpFlexModes(modes) {
147
+ export function reduceOtpFlexModes(modes, enabled = true) {
148
+ if (!enabled) return modes;
149
+
152
150
  return modes.reduce((prev, cur) => {
153
151
  const newModes = prev;
154
152
  // Add the current mode if it is not a flex mode
@@ -191,7 +189,10 @@ export function expandOtpFlexMode(mode) {
191
189
  * default values.
192
190
  */
193
191
  export function isNotDefaultQuery(query, config) {
194
- const activeModes = reduceOtpFlexModes(query.mode.split(",").sort());
192
+ const activeModes = reduceOtpFlexModes(
193
+ query.mode.split(",").sort(),
194
+ config.modes?.mergeFlex
195
+ );
195
196
  if (
196
197
  activeModes.length !== 2 ||
197
198
  activeModes[0] !== "TRANSIT" ||
@@ -427,7 +428,7 @@ export function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
427
428
  }
428
429
 
429
430
  // check date/time validity; ignore both if either is invalid
430
- const dateValid = isMatch(params.date, OTP_API_DATE_FORMAT_DATE_FNS);
431
+ const dateValid = isMatch(params.date, OTP_API_DATE_FORMAT);
431
432
  const timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);
432
433
 
433
434
  if (!dateValid || !timeValid) {
@@ -470,7 +471,8 @@ export function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
470
471
  }
471
472
 
472
473
  // Replace FLEX placeholder with OTP flex modes
473
- if (params.mode) {
474
+ // Explicit false check allows avoiding a breaking change -- undefined is true
475
+ if (params.mode && config.modes?.mergeFlex !== false) {
474
476
  // Ensure query is in reduced format to avoid replacing twice
475
477
  const reducedMode = reduceOtpFlexModes(params.mode.split(",")).join(",");
476
478
  params.mode = expandOtpFlexMode(reducedMode);
package/src/time.ts CHANGED
@@ -2,12 +2,9 @@ import { Config } from "@opentripplanner/types";
2
2
  import { startOfDay, add, format } from "date-fns";
3
3
  import { utcToZonedTime } from "date-fns-tz";
4
4
 
5
- // special constants for making sure the following date format is always sent to
6
- // OTP regardless of whatever the user has configured as the display format
7
- export const OTP_API_DATE_FORMAT = "YYYY-MM-DD";
8
- // Date-Fns uses a different string format than moment.js
9
- // see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
10
- export const OTP_API_DATE_FORMAT_DATE_FNS = "yyyy-MM-dd";
5
+ // Date/time formats (per date-fns) when sending/receiving date from OTP
6
+ // regardless of whatever the user has configured as the display format.
7
+ export const OTP_API_DATE_FORMAT = "yyyy-MM-dd";
11
8
  export const OTP_API_TIME_FORMAT = "HH:mm";
12
9
 
13
10
  /**
@@ -89,8 +86,5 @@ export function getCurrentTime(timezone = getUserTimezone()): string {
89
86
  * The conversion to the user's timezone is needed for testing purposes.
90
87
  */
91
88
  export function getCurrentDate(timezone = getUserTimezone()): string {
92
- return format(
93
- utcToZonedTime(Date.now(), timezone),
94
- OTP_API_DATE_FORMAT_DATE_FNS
95
- );
89
+ return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);
96
90
  }