@@ -595,28 +595,31 @@ export function calculateEmissions(
595595}
596596
597597/**
598- * Returns the user-facing stop id to display for a stop or place, using the following priority:
599- * 1. stop code,
600- * 2. stop id without the agency id portion, if stop id contains an agency portion,
601- * 3. stop id, whether null or not (this is the fallback case).
598+ * Returns the user-facing stop code to display for a stop or place
602599 */
603- export function getDisplayedStopId ( placeOrStop : Place | Stop ) : string {
604- let stopId ;
605- let stopCode ;
600+ export function getDisplayedStopCode (
601+ placeOrStop : Place | Stop
602+ ) : string | undefined {
606603 if ( "stopId" in placeOrStop ) {
607- ( { stopCode, stopId } = placeOrStop ) ;
608- } else if ( "id" in placeOrStop ) {
609- ( { code : stopCode , id : stopId } = placeOrStop ) ;
604+ return placeOrStop . stopCode ?? undefined ;
610605 }
611- return stopCode || stopId ?. split ( ":" ) [ 1 ] || stopId ;
606+ if ( "id" in placeOrStop ) {
607+ return placeOrStop . code ?? undefined ;
608+ }
609+ return undefined ;
612610}
613611
614612/**
615613 * Removes the first part of the OTP standard scope (":"), if it is present
614+ * If it's null or undefined, return the original value.
616615 * @param item String that is potentially scoped with `:` character
617616 * @returns descoped string
618617 */
619- export const descope = ( item : string ) : string => item ?. split ( ":" ) ?. [ 1 ] ;
618+ export const descope = ( item ?: string | null ) : string | null | undefined => {
619+ if ( ! item ) return item ;
620+ const index = item . indexOf ( ":" ) ;
621+ return index === - 1 ? item : item . substring ( index + 1 ) ;
622+ } ;
620623
621624export type ExtendedMoney = Money & { originalAmount ?: number } ;
622625
@@ -638,8 +641,8 @@ export const zeroDollars = (currency: Currency): Money => ({
638641 */
639642export function getLegCost (
640643 leg : Leg ,
641- mediumId : string | null ,
642- riderCategoryId : string | null ,
644+ mediumId ? : string | null ,
645+ riderCategoryId ? : string | null ,
643646 seenFareIds ?: string [ ]
644647) : {
645648 alternateFareProducts ?: AppliedFareProduct [ ] ;
@@ -662,6 +665,7 @@ export function getLegCost(
662665
663666 const productMediaId =
664667 descope ( product ?. medium ?. id ) || product ?. medium ?. id || null ;
668+
665669 return (
666670 productRiderCategoryId === riderCategoryId &&
667671 productMediaId === mediumId &&
@@ -709,8 +713,8 @@ export function getLegCost(
709713 */
710714export function getItineraryCost (
711715 legs : Leg [ ] ,
712- mediumId : string | string [ ] | null ,
713- riderCategoryId : string | string [ ] | null
716+ mediumId ? : string | string [ ] | null ,
717+ riderCategoryId ? : string | string [ ] | null
714718) : Money | undefined {
715719 // TODO: Better input type handling
716720 if ( Array . isArray ( mediumId ) || Array . isArray ( riderCategoryId ) ) {
@@ -772,7 +776,7 @@ export function getItineraryCost(
772776 ) ;
773777}
774778
775- const pickupDropoffTypeToOtp1 = otp2Type => {
779+ const pickupDropoffTypeToOtp1 = ( otp2Type : string ) : string | null => {
776780 switch ( otp2Type ) {
777781 case "COORDINATE_WITH_DRIVER" :
778782 return "coordinateWithDriver" ;
0 commit comments